将 HTTPS 重定向到 HTTP

将 HTTPS 重定向到 HTTP

问题:我无法将我的网站从 https 重定向到 http。

好的,有很多解决方案,但似乎没有一个对我有用。先确定几点,我已经在这个网站上很好地运行了 .htaccess,因此设置 AllowOverride 的需要已经不复存在了。

我见过的最基本的是添加类似以下内容的内容:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

...到我的 .htaccess 文件。然而这什么都没做……好像条件没有得到满足。设置并访问后https://mysite.com我没有被重定向到http://mysite.com正如我所料,我宁愿简单地通过https://mysite.com

这是什么原因造成的?我的期望是,如果 .htaccess 文件中有上述内容,并且 .htaccess 文件在我的网站上运行良好,那么当我访问任何 https 网址时,我都会被重定向到其 http 等效网址。


更多信息

在临时服务器上 在我的临时服务器上,将上述内容添加到 htaccess 会将我发送到一个带有附加参数的 URL,例如http://mystaging-site.com/?ysid=2pnd073423ra966tihf22rfr9a2

在生产服务器上 对生产结果进行快速测试会出现一个 apache 错误页面,提示页面已被移动并且出现 500 服务器错误。

错误信息具体如下:

Found

The document has moved here. <--- this link simply points to the same page I am already on

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

现有的 htaccess 如下:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

并且以下操作失败:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} =on  //(with or without the equals symbol this fails)
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTP_HOST} !^www.mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

答案1

接近,但不完全,尝试:

RewriteEngine On
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]

相关内容