问题描述
我正在尝试将所有HTTP请求重定向到HTTPS,并将所有www重定向到非www URL.
I'm trying to redirect all HTTP requests to HTTPS and all www to non-www URLs.
也就是说,
- http://example.net 到 https://example.net
- http://www.example.net 到 https://example.net
- http://www.example.net 到 https://example.net
- https://www.example.net 到 https://example.net
- http://example.net to https://example.net
- http://www.example.net to https://example.net
- http://www.example.net to https://example.net
- https://www.example.net to https://example.net
我成功地能够重定向URL条件(1、2和3),但是第4个重定向条件不起作用,即 https://www.example.net 到 https://example.net .
I was successfully able to redirect URL conditions (1, 2 & 3) but the 4th redirect condition does not work, i.e. https://www.example.net to https://example.net.
我为我的网站的www和非www URL都具有SSL证书.我当前正在使用WordPress.
I have an SSL certificate for both www and non-www URLs for my website. I'm currently using WordPress.
我的.htaccess文件包含以下代码:
My .htaccess file contains the following code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
我尝试了许多不同的重定向条件,但是没有一个起作用.
I've tried many different redirect conditions but none worked.
我在Firefox中收到以下错误:
I get the following error in Firefox:
我该怎么做才能重定向第四个URL条件?
What can I do to redirect the 4th URL condition?
推荐答案
我终于找到了解决问题的方法.是CloudFare,我使用的是免费版本.
I finally found the solution to the problem. It is CloudFare, I was using the free version.
通过Cpanel为我的网站关闭cloudfare可使所有重定向正常工作.
Turning off cloudfare for my website from Cpanel made all the redirects work.
这篇关于将HTTP重定向到HTTPS并将WWW重定向到NON-WWW URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!