WordPress https重定向循环

时间:2015-07-21 08:12:50

标签: php wordpress .htaccess ssl

我尝试使用SSL将WordPress博客设置为域上的子文件夹但没有成功。如果将博客.htaccess设置为将所有HTTP重定向到HTTPS,则会导致重定向循环。如果.htaccess未设置为将所有HTTP重定向到HTTPS,则博客无法正常显示,因为浏览器在使用SSL时阻止所有HTTP请求,在这种情况下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

这是博客文件夹.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网址,唯一的例子是样本页面和帖子网址,但这并没有帮助解决问题。

1 个答案:

答案 0 :(得分:3)

我能够通过在&#39;上添加$ _SERVER [&#39; HTTPS&#39;] =&#39;来解决问题。进入wp-config.php。我不知道为什么系统没有正确设置$ _SERVER [&#39; HTTPS&#39;],但我猜它在某种程度上与Apache / SSL配置有关。

未设置$ _SERVER [&#39; HTTPS&#39;] =&#39; on&#39; WP无法检测HTTPS并且正在通过HTTP加载内容,而.htaccess重定向导致重定向循环。