【问题标题】:WordPress https redirect loopWordPress https 重定向循环
【发布时间】:2015-10-10 14:08:09
【问题描述】:

我正在尝试使用 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 数据库中手动将所有 HTTP url 替换为 HTTPS,唯一出现的是示例页面和发布 url,但这无助于解决问题。

【问题讨论】:

    标签: php wordpress .htaccess ssl


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      • 2019-07-10
      • 2013-11-27
      • 1970-01-01
      • 2015-01-27
      • 2021-09-15
      • 1970-01-01
      相关资源
      最近更新 更多