Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having some trouble with mod_rewrite. So I'm implementing it through .htaccess, and I can get it working on my main vhost, domain.com - what I want it to do is rewrite http://domain.com to force it to https://domain.com, which it does well. I want to have name-based vhosts for the one IP with the following redirects:

http://domain.com --> https://domain.com
http://staging.domain.com --> https://staging.domain.com
http://test.domain.com --> https://test.domain.com
http://beta.domain.com --> https://beta.domain.com

domain.com redirects to https://domain.com, but staging.domain.com doesn't, although I can access https://staging.domain.com. The .htaccess is identical for both, just with the domain name different. It doesn't seem to do any rewriting at all for staging.domain.com, I've tested this by trying to get it to rewrite to www.google.com.

I have a wildcard DNS record, *.domain.com which points to the domain IP.

Is there a particular way I should have the virtualhosts configured to allow this?

I keep reading in the Apache documentation that it doesn't support multiple SSL name-based vhosts. But I can access both https://domain.com and https://staging.domain.com just fine.

Any thoughts? Thanks to everyone for your help with this.

share|improve this question

2 Answers 2

Do you have an "NameVirtualHost" directive? And are you using them in your vhost configuration?

Besides please take a look at this: http://wiki.apache.org/httpd/NameBasedSSLVHosts

If both SSL domains are running on the same IP, only one encryption (certificate) will be used and "clients will receive certificate mismatch warnings and be vulnerable to man-in-the-middle attacks".

share|improve this answer
    
yes, I've specified two namevirtualhost directives, !ip:80 and !ip:443. They're both in the default site. With these enabled, URL rewriting doesn't work at all –  Matt Jan 8 '11 at 23:59
1  
Ok do you have an "AllowOverride" Setting in your vhost configuration?You could also try to put the stuff from your .htaccess into your "<directory> directive. See httpd.apache.org/docs/current/howto/htaccess.html –  shakalandy Jan 9 '11 at 1:32

RewriteEngine can be enabled both globally and on a per-vhost basis. Even if enabled globally, the options don't carry into vhosts by default. You probably just need to turn it back on in the current vhost. RewriteEngine on (and possibly RewriteOptions inherit, depending upon your configuration) in each vhost.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.