WordPress https重定向循环


WordPress https redirect loop

我正在尝试使用SSL将WordPress博客设置为域上的子文件夹,但没有成功。如果将blog .htaccess设置为将所有HTTP重定向到HTTPS,则会导致重定向循环。如果.htaccess没有设置为将所有HTTP重定向到HTTPS,那么博客将无法正常显示,因为浏览器正在阻止所有HTTP请求,因为SSL正在使用中,在这种情况下wp登录也会失败。

Details:
- Fresh WordPress installation
- Domain is using SSL
- WP installed on subfolder example.com/blog/
- HTTPS set to WP's home and site URL in database
这是blog文件夹。htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /blog/
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

这里是主域名。htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www'.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !'..+$
RewriteRule ^(.*)$ http://foobar.example.com/$1 [L,R=301]
下面是apache的http请求配置:/etc/apache2/sites-available/000 - default.conf
<VirtualHost *:80>
   ServerName example.com
   ServerAlias *.example.com
   ServerSignature Off
   RewriteEngine on
   RewriteCond %{HTTPS} !=on
   RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]
</VirtualHost>

任何帮助和想法将不胜感激。

更新:我在WP数据库中用HTTPS手动替换了所有HTTP url,唯一出现的是示例页面和帖子url,但这并没有帮助解决问题。

我可以通过添加$_SERVER['HTTPS']='on'来解决这个问题;wp-config.php。我不知道为什么$_SERVER['HTTPS']没有被系统正确设置,但我猜它与Apache/SSL配置有关。

没有设置$_SERVER['HTTPS']='on', WP无法检测HTTPS,正在通过HTTP加载内容,使用。htaccess重定向导致重定向循环。