简体   繁体   中英

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://.

Here is the htaccess file:

<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...

I tried to deactivate all plugins, remove htaccess file, none of those worked.

Thanks a lot.

Don't use RewriteRules for the HTTP to HTTPS redirect. 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.

<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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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