Search code examples
wordpressapache.htaccesscwp

HTTP to HTTPS too many redirections


I encountered this strange issue that whenever I add this most generally used htaccess code, I get too many redirections.

Scenario:

+public_html
|
|--- WordPress 1
|--- .htaccess
 --+ /blog
   |
   |--WordPress 2
    --.htaccess

.htaccess (WordPress 2)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.test/blog/$1 [R=301,L]

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#RewriteCond %{HTTPS} off
#RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
  
</IfModule>

# END WordPress

Whenever I add HTTPS redirection code in any of the htaccess it gives Too many redirects.

It seems RewriteCond %{HTTPS} off this condition is always getting true and that's why (Checked here: http://htaccess.madewithlove.be/) How can I tackle this?

Notes: WordPress home/site URL is set correctly: https://domain.test/blog for WordPress 2

Edit: Solution: The issue was Flexible mode in Cloudflare. When I set it to Full SSL mode in Cloudflare the issue was solved.


Solution

  • The issue was Flexible mode in Cloudflare. When I set it to Full SSL mode in Cloudflare the issue was solved.