Monday, March 21, 2016

virtualhost - Apache redirect seems to ignore ServerName

I have a couple virtual host files. The first one redirects all traffic for http://www.mysite.com to the https version:




ServerName www.mysite.com
Redirect permanent / https://www.mysite.com/




ServerName www.mysite.com
# additional configuration



The second defines a VirtualDocumentRoot so that sites in directories such as /var/www/www.othersite.com will be served.




ServerAdmin webmaster@localhost
VirtualDocumentRoot /var/www/%0

VirtualScriptAlias /var/www/%0/cgi-bin/



I also have NameVirtualHost definitions in the ports.conf file (in case that is helpful):



NameVirtualHost *:443
NameVirtualHost *:80



The problem is that all traffic seems to be redirected to https://www.mysite.com. I would expect that the ServerName www.mysite.com line in the first virtual host file would only match www.mysite.com so that visiting http://www.othersite.com would serve content from /var/www/www.othersite.com. When I comment out the entire port 80 VirtualHost definition from the first file, http://www.othersite.com loads as expected. Am I missing something here? How do I only redirect http to https for www.mysite.com?



Edit:



The reason I can't put the ServerName as http://www.othersite.com in the second VirtualHost definition is that there are multiple sites in /var/www that also need to be served.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...