PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, September 21, 2022

[FIXED] How can i set htaccess file for virtual host?

 September 21, 2022     .htaccess, apache, ubuntu-16.04, virtualhost     No comments   

Issue

I created a virtual host with this code :

<VirtualHost *:80>

    ServerAdmin admin@127.0.0.1
    ServerName site.ws
    ServerAlias www.site.ws
    DocumentRoot /home/me/Projects/website/build
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<Directory /home/me/Projects/website/build>

        Allow from all
        Satisfy any

</Directory>

</VirtualHost>

and I created a .htaccess file in my /build directory with this code :

RewriteEngine On

RewriteRule   ^(.*)$    $1.html    [R,NC]

Consider my mod_rewrite is active in apache2, but I can't open pages with /filename

e.g site.ws/about

It shows error : The requested URL /about was not found on this server.


Solution

I try this with Apache2 2.4.27 in win:

First enable vhost in httpd.conf file.

vhost:

<VirtualHost *:80>
    ServerName site.ws
    DocumentRoot /home/me/Projects/website/build
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /home/me/Projects/website/build>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

.htaccess:

###START MOD_REWRITE
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #REMOVE .html EXTENSION
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.html [NC,L]

</IfModule>
###END MOD_REWRITE


Answered By - benny-ben
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing