WordPress https重定向循环
问题描述:
我试图将WordPress博客设置为使用SSL的域上的子文件夹而没有成功。如果博客.htaccess设置为将所有HTTP重定向到HTTPS,则会导致重定向循环。如果.htaccess未设置为将所有HTTP重定向到HTTPS,则由于SSL正在使用中,因为浏览器正在阻止所有HTTP请求,所以博客无法正常显示,在这种情况下,wp登录失败。WordPress https重定向循环
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
这里是博客文件夹的.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]
这里是HTTP请求Apache的配置: 的/ 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重定向导致重定向循环。