Question

I've been scouring the net and SO and I can't get around or through this problem.

We have a bunch of subdomains and a few dedicated servers. One server does double-triple duty as issue tracking and landing page. Problem is the wildcard landing page doesn't take you to the correct virtual host page sometimes. I've been looking at wildcards but they seem particularly broad.

Our scenario is the following:

-www.askia.com is the main landing site. A non-existing (wildcard) subdomain should always land here.
-dev.askia.com is the technical support and issues site. It has some mod_rewrites for https. It took me a while, but I got it to work and I'd rather not break it.
-www.askia.fr is our french site. Instead of taking you to www.askia.com it takes you to the dev.askia.com.
-www.askia.co.uk should take you to www.askia.com but it goes to dev.askia.com

I'm not entirely sure where I should be trying to fix the solution. Should I do something in the CNAME. In the virtualhosts config file or in the mod_rewrite file.

Was it helpful?

Solution

Try these rules:

RewriteCond %{HTTP_HOST} ^dev\.
RewriteCond %{HTTP_HOST} !^dev\.askia\.com$
RewriteRule ^ http://dev.askia.com%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.askia\.com$
RewriteCond %{HTTP_HOST} !^dev\.askia\.com$
RewriteRule ^ http://www.askia.com%{REQUEST_URI} [L,R=301]

The first rule redirects every request to a host starting with dev. but not dev.askia.com to www.askia.com. And the second rule redirect requests to a host other than www.askia.com and dev.askia.com to www.askia.com. So every request should either go to dev.askia.com or www.askia.com.

OTHER TIPS

When using Virtual Hosts in Apache the first hosted listed will always be the default for non-matches.

#default vhost
# any non-matches will land here

<VirtualHost  _default_:80>
ServerName www.askia.com:80
DocumentRoot /path/to/site

ErrorLog /path/ti/sites/logs/error_log

</VirtualHost>


# vhost #2 

<VirtualHost  _dev_Site_:443>
ServerName dev.askia.com:443
DocumentRoot /path/to/dev/site

ErrorLog /path/to/dev/sites/logs/error_log

#ssl details
SSLEngine on
SSLCipherSuite HIGH:MEDIUM
SSLCertificateFile /location/securti.crt
SSLCertificateKeyFile /location/securti.key


#any rewrite rules to apply only to this (default) domain
# force SSL for instance..
RewriteRule .* - [F]
RewriteCond   %{SERVER_PORT}  !^443$
RewriteRule (.*) https://dev.askia.com/
</VirtualHost>

#etc, etc
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top