Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i set htaccess file for virtual host?

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.

like image 757
Mohammad Avatar asked Oct 16 '25 11:10

Mohammad


1 Answers

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
like image 125
benny-ben Avatar answered Oct 18 '25 10:10

benny-ben



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!