views:

903

answers:

2

Hi guys, I've got some issues with the .htaccess that I just can't get to work. Hope someone could solve this one.

I have a SSL certificate on the www.-domain on an Apache server. I want all http://subdomain.domain.com requests on a specified list of subdomains to redirect to https://www.domain.com/subdomain.

The second problem is, that since I don't have a wildcard certificate that works on non-www.-requests, requests to https://subdomain.domain.com will result in an "Untrusted Connection" alert. So this also has to be solved, but maybe it requires another type of redirect?

What conditions and rules could achieve these two requirements using .htaccess?

+1  A: 

Try this rule:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(specific|list|of|subdomains)\.example\.com$
RewriteRule ^ http://www.example.com/%1%{REQUEST_URI}
Gumbo
Thanks buddy.The second requirement still doesn't work though. I'm not sure, but maybe the server first checks the SSL and then the .htaccess? How should I solve it in that case?
Calle
That worked when I removed the subdomain from being a "subdomain", but kept the folder in the filesystem!By the way, how should I change the rule so that parameters are passed on as well? Like: http://subdomain.domain.com/folder => https://www.domain.com/subdomain/folder?
Calle
A: 

If you use mod-rewrite, it will appear to the user that they are using subdomain.domain.com while the actual files are being served by the webserver out of www.domain.com/subdomain. unfortunately, the webserver will be sending the ssl certificate for www.domain.com, leading to a domain mismatch and causing the user's browser to complain. there is nothing you can do about this.

one option is to come clean to your users and simply redirect them to www.domain.com/subdomain instead of rewriting their requests. you can use the apache Redirect directive to do this, or you can just send a Location: header back from a placeholder html file.

Igor
Yeah, I was afraid it wasn't solvable using a "hidden" redirect. Damn =)
Calle
No, it actually worked... I removed the subdomain from being a "subdomain", but kept the folder in the filesystem!
Calle