简体   繁体   English

Apache(htaccess)重定向循环http https

[英]Apache (htaccess) redirect loop http https

We are experiencing a redirect loop on Wordpress homepage and I have no idea where does it come from, we switched the URL to http://www to https://. 我们正在Wordpress主页上遇到重定向循环,但我不知道它来自何处,我们将URL从http:// www切换为https://。

Here is the htaccess file: 这是htaccess文件:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

http://scrybs.com is redirecting to http://www.scrybs.com and http://www.scrybs.com is causing a redirect loop... http://scrybs.com重定向到http://www.scrybs.com,http://www.scrybs.com导致重定向循环...

I tried to deactivate all plugins, remove htaccess file, none of those worked. 我试图停用所有插件,删除htaccess文件,但没有一个起作用。

Thanks a lot. 非常感谢。

Don't use RewriteRules for the HTTP to HTTPS redirect. 不要将RewriteRules用于HTTP到HTTPS的重定向。 Change it to have the HTTP (port 80) virtual host redirect to the HTTPS (port 443) virtual host and put all your configuration in the HTTPS (port 443) configuration. 对其进行更改,以使HTTP(端口80)虚拟主机重定向到HTTPS(端口443)虚拟主机,并将所有配置放入HTTPS(端口443)配置。

<VirtualHost *:80>
    ServerName www.example.com
    Redirect "/" "https://www.example.com/"
</VirtualHost >

<VirtualHost *:443>
    ServerName www.example.com
    # ... SSL configuration goes here
</VirtualHost >

Ref: https://httpd.apache.org/docs/2.4/rewrite/avoid.html 参考: https : //httpd.apache.org/docs/2.4/rewrite/avoid.html

Then, remove these lines: 然后,删除以下行:

RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

You may want to restore the www configuration, but without the HTTPS update. 您可能要还原www配置,但不进行HTTPS更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM