【问题标题】:.htaccess redirect to https is not working.htaccess 重定向到 https 不起作用
【发布时间】:2018-04-29 11:41:10
【问题描述】:
我数小时都在摸不着头脑,尝试了许多解决方案,但仍然无法将我的网站重定向到 https。
下面是我的.htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
另一个 .htaccess 我试过了:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
两者都不起作用,我还在 stackoverflow 上尝试了许多其他解决方案。但没有一个工作。
作为参考,这里是https Link of my website.
【问题讨论】:
标签:
.htaccess
redirect
url-redirection
http-redirect
【解决方案1】:
一年前我遇到了这个问题。尝试在您放置 .htaccess 文件的根目录中添加 web.config 文件。
在web.config中复制并粘贴以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
【解决方案2】:
试试
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]