I've got some issues with a .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 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
?
Try this rule:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(specific|list|of|subdomains)\.example\.com$
RewriteRule ^ http://www.example.com/%1%{REQUEST_URI}
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.