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.
2
Answers
The issue was Flexible mode in Cloudflare. When I set it to Full SSL mode in Cloudflare the issue was solved.
In your file ‘.htaccess WordPress 2 you have a mistake.
This is causing you problems. What happens:
http://www.domain.test/blog
RewriteCond %{HTTPS} off
will trigger, since you are usinghttp
and nothttps
This part:
^(.*)$
means:take everything from beginning (
^
) to end ($
). (In your case that isblog
.)Put that part into a variable. That is the parentheses part
(.*)
means. It will make the ‘everything’ part available as variable$1
Putting this together, you should now replace
$1
withblog
. The end result being:https://www.domain.test/blog/blog/
So, you should start by removing the
blog
part of your third line:New problems might occur, but you have to fix this first.