Redirect subdomain request to subdirectory + https (using .htaccess)

∥☆過路亽.° 提交于 2020-01-02 09:10:15

问题


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?


回答1:


Try this rule:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(specific|list|of|subdomains)\.example\.com$
RewriteRule ^ http://www.example.com/%1%{REQUEST_URI}



回答2:


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.



来源:https://stackoverflow.com/questions/1545097/redirect-subdomain-request-to-subdirectory-https-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!