views:

887

answers:

3

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.

+1  A: 

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.

Gumbo
thanks I'll give this a shot. If I add other subdomains I need to add them to the rewreitecond?
Joe Chin
Yes. My example only allows `dev.…` and `www\.…`. Host names with another beginning would be redirected to `www.askia.com`.
Gumbo
A: 

Okay I think I found something else. I found a post here about each conf file. I typed apache2ctl -S and this is the printout I'm getting:

VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:443 is a NameVirtualHost default server dev.askia.com (/etc/apache2/sites-enabled/dev.askia.com:91) port 443 namevhost dev.askia.com (/etc/apache2/sites-enabled/dev.askia.com:91) *:80 is a NameVirtualHost default server dev.askia.com (/etc/apache2/sites-enabled/dev.askia.com:3) port 80 namevhost dev.askia.com (/etc/apache2/sites-enabled/dev.askia.com:3) port 80 namevhost www.askia.com (/etc/apache2/sites-enabled/www.askia.com:1) Syntax OK

So it looks like the problem isn't with the rewrites but the way apache determines the default site. It seems completely random because when I disable dev it defaults to www I've configured a 000-default file but it doesn't show up at all.

Joe Chin
A: 

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
Eddie
So how do I change this order. The only thing I have in the apache2.conf is a reference to the sites-enabled directory. I can't find anything on how to change this order, except unloading the default site which is impractical.
Joe Chin
joe - whatever domain is first will be your catch all. To change that just list another one first.I edited my original post to include a sample vhost config that makes www your default and forces dev. to be ssl.
Eddie