Question
Apache vhost issue, two domains, second redirects to first ?
Hello,
I have two domains say for example site1.co.uk and site2.uk
I have set my web directory up to be like /var/www/site1.co.uk/www and /var/www/site2.uk/www.
For the vhost conf file for each domain, I have pointed the docroot to the nessesary directory.
Here is an example of my config files:
site1.co.uk.conf
<VirtualHost *:80>
ServerAdmin email@site1.co.uk
ServerName site1.co.uk
ServerAlias www.site1.co.uk
DocumentRoot /var/www/site1.co.uk/www
ErrorLog ${APACHELOGDIR}/error.log
CustomLog ${APACHELOGDIR}/access.log combined
</VirtualHost>
site2.uk.conf
<VirtualHost *:80>
ServerAdmin email@site2.uk
ServerName site2.uk
ServerAlias www.site2.uk
DocumentRoot /var/www/site2.uk/www
ErrorLog ${APACHELOGDIR}/error.log
CustomLog ${APACHELOGDIR}/access.log combined
</VirtualHost>
I have also ran these commands:
a2ensite site1.co.uk.conf
a2ensite site2.uk.conf
service apache2 reload
Now when I enter site1.co.uk or www.site1.co.uk in my browser. No problem. The website loads, the correct doc root loads etc.
When I load site2.uk or www.site2.uk it just redirects to www.site1.co.uk. I have installed a headers extension on my browser and it is telling me it gives Status: HTTP/1.1 301 Moved Permanently.
Can anyone give me pointers how to correct this issue?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
It looks good, but did you tried restart instead of reload? Just to be sure:
If you use Ubuntu 14.04 or older:
Hi , yeah i have tried both of them . With and without sudo . I have also a2dissite all the vhosts and then a2ensite them back again before restarting.
From my understanding Apache routes to the default vhost a sort of catch all . But I have a specific vhost for site2.uk so don’t understand why it is redirecting me to the default