我遇到了这个奇怪的问题,每当我添加这个最常用的 htaccess 代码时,我都会得到太多的重定向。
设想:
+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
每当我在任何 htaccess 中添加 HTTPS 重定向代码时,它都会提供太多重定向。
似乎 RewriteCond %{HTTPS} 关闭这种情况总是正确的,这就是为什么(在这里检查:http: //htaccess.madewithlove.be/)我该如何解决这个问题?
注意:WordPress 主页/站点 URL 设置正确:WordPress 2 的https://domain.test/blog
编辑:解决方案:问题是 Cloudflare 中的灵活模式。当我在 Cloudflare 中将其设置为完全 SSL 模式时,问题就解决了。