[英]http:// to https://www redirect not working
I want to redirect http://
to https://www
.我想将
http://
重定向到https://www
。 Now it is redirecting https://
then https://www
现在它正在重定向
https://
然后https://www
I am using siteground I tried many answers given on StackOverflow.我正在使用 siteground 我尝试了 StackOverflow 上给出的许多答案。
Example of codes I tried:我试过的代码示例:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301]
<IfModule mod_rewrite.c>
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
You were close you need not to use OR
condition after checking https condition, could you please try following.在检查 https 条件后,您很接近您不需要使用
OR
条件,请您尝试以下操作。 Following rules should apply https to a non http
url with/without www
.以下规则应将 https 应用于带/不带
www
的非http
url 。
Please make sure you clear your browser cache before you test your URLs.请确保在测试 URL 之前清除浏览器缓存。
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
If you are using Cloudflare CDN
or any other proxy server then you will need to match against %{HTTP:X-Forwarded-Proto}
variable to detect the URL scheme.如果您使用
Cloudflare CDN
或任何其他代理服务器,则需要匹配%{HTTP:X-Forwarded-Proto}
变量以检测 URL 方案。 You can use the following rule that redirects http
and https-noWWW
to https://www
in a single request:您可以使用以下规则在单个请求
http
和https-noWWW
重定向到https://www
:
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} http$ [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule (.*) https://www.%1%{REQUEST_URI} [L,R=301]
Make sure you clear your browser cache before testing this rule.确保在测试此规则之前清除浏览器缓存。
This is the perfect redirection这是完美的重定向
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
the redirect rules mentioned here is perfect but will work only if you disable server-side redirect.这里提到的重定向规则是完美的,但只有在禁用服务器端重定向时才有效。
In your siteground hosting account Goto site tools > Security > HTTPS enforce and disable it在您的站点托管帐户中转到站点工具>安全> HTTPS强制并禁用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.