将子域请求重定向到子目录 + https(使用 .htaccess)
我的 .htaccess
遇到了一些问题,我无法正常工作。希望有人能解决这个问题。
我在 Apache 服务器上的 www.-domain 上有一个 SSL 证书。我希望指定的子域列表上的所有 http://subdomain.domain.com
请求都重定向到 https://www.domain.com/subdomain
。
第二个问题是我没有适用于非 www 的通配符证书。请求,对 https://subdomain.domain.com
的请求将导致“不受信任的连接”警报。所以这也必须解决,但也许它需要另一种类型的重定向?
使用.htaccess
需要什么条件和规则才能达到这两个要求?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个规则:
Try this rule:
如果您使用 mod-rewrite,用户会觉得他们正在使用 subdomain.domain.com,而实际文件则由 www.domain.com/subdomain 之外的网络服务器提供服务。不幸的是,网络服务器将发送 www.domain.com 的 ssl 证书,导致域不匹配并导致用户的浏览器抱怨。你对此无能为力。
一种选择是向用户坦白并简单地将他们重定向到 www.domain.com/subdomain,而不是重写他们的请求。您可以使用 apache Redirect 指令来执行此操作,或者您可以从占位符 html 文件发回一个 Location: 标头。
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.