How can i set htaccess file for virtual host?
12,072
Solution 1
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
Solution 2
i solved this problem with :
RewriteEngine On
RewriteRule ^([a-zA-Z-]+)$ $1.html [L,NC]
Comments
-
Mohammad almost 2 years
I created a virtual host with this code :
<VirtualHost *:80> ServerAdmin [email protected] 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.