mod_rewrite apache 的问题 |将非 www 网址重定向到 www 网址
我试图将我网站上的所有请求重定向到以下格式的 url:
https://www.mydomain.com
因为我有 www.mydomain.com
的 SSL 证书。我在我的 httpd.conf
文件中编写了以下重写规则来执行此操作:
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule $ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteCond %{HTTPS} off
RewriteRule $ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
在以下可能的格式中,只有一种不起作用:
mydomain.com - working
www.mydomain.com - working
http://mydomain.com - working
https://mydomain.com – not working
https://www.mydomain.com - working
http://www.mydomain.com - working
任何人都可以解释此问题背后的原因和解决方案吗?
更新:
当我尝试访问不起作用的 URL (https://mydomain.com
) 时,我收到无效的 SSL 证书错误(因为我的证书有效)对于 www.mydomain.com
而不是 mydomain.com
),因此我的重写规则没有被执行,因为尚未建立 http 连接。
这个问题有什么解决办法吗?
I am trying to redirect all request on my site to url of format:
https://www.mydomain.com
as I have SSL certificate for www.mydomain.com
. I have written following rewrite rules in my httpd.conf
file to do this:
RewriteCond %{HTTP_HOST} !^www [NC]
RewriteRule $ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]
RewriteCond %{HTTPS} off
RewriteRule $ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
Out of the following possible formats, only one is not working:
mydomain.com - working
www.mydomain.com - working
http://mydomain.com - working
https://mydomain.com – not working
https://www.mydomain.com - working
http://www.mydomain.com - working
Can anyone explain the reason behind and solution for this issue?
Update:
When I try to hit the URL which is not working (https://mydomain.com
), I get an invalid SSL certificate error (as my certificate is valid for www.mydomain.com
and not mydomain.com
) and hence none of my Rewrite rule is getting executed as http connection is not yet made.
Is there any solution for this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可能想尝试
而不是
you may want to try
instead of
以我拥有的证书这是不可能的。尝试https://amazon.com,您将看到不受信任的连接问题。我有类似的问题。选择是购买另一个证书。
This is not possible with the certificate that I have. Try https://amazon.com and you will see the untrusted connection problem. I have similar issue. Option is to buy another certificate.