Php – Xampp virtual hosts file messes up when an httpd redirect is put in place

PHPvirtualhostxampp

Below is my httpd-vhosts.conf file for reference on my Windows 7 machine running xampp 1.7.4:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot C:/xampp/htdocs
    ServerName localhost
    ServerAlias localhost

    <Directory "C:/xampp/htdocs">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@new_site
    DocumentRoot C:/xampp/htdocs/new_site
    ServerName new_site
    ServerAlias new_site

    <Directory "C:/xampp/htdocs/new_site">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

I cannot even being to guess why but running https on any localhost directory (even https://localhost/new_site works fine) but running https://new_site generates a 404 error.

I am aware that port 443 is typically used in https redirects but adding this to the virtualhost configuration file causes apache to stop running altogether. Also, port 443 is never defined for localhost in the same file so it makes me think it is not necessary.

Best Answer

Apache is happy with this config, your DNS however... Not so much. You need to tell your computer that you aren't only localhost but also new_site.

You can do this by editing your hosts-file, located at %systemroot%\system32\drivers\etc\hosts. Add this line:

127.0.0.1 new_site

Or add a new A-record to your DNS if you are running one.

In order for https to work you need to add your site to ssl.conf or httpd-ssl.conf, your localhost should be defined here also.

Related Topic