Skip to content Skip to sidebar Skip to footer

Apache VirtualHost Not Working Correctly

Problems The problem I'm having is getting the VirtualHost to work right. This is how I have the two setup: DocumentRoot '/Apps/XAMPP/htdocs' Serv

Solution 1:

Firstly you are really close. Be sure that mod_rewrite apache module is enabled. Secondly you do not need two virtual hosts, so you can merge them like so (I left the paths untouched): .

<VirtualHost *:80>
    DocumentRoot "/Apps/XAMPP/htdocs"
    ServerName wrks.tk
    ServerName www.wrks.tk
    ErrorLog "/Logs/Workarea/Error.log"
    CustomLog "/Logs/Workarea/Access.log" common
    <Directory "/Apps/XAMPP/htdocs/Workspace">
        AllowOverride all
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Now in the directory htdocs create a file .htaccess with content:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

Remove completly the REDIR dir with the contents. This will htaccess will redirect website which starts with www.to a non-www.


Post a Comment for "Apache VirtualHost Not Working Correctly"