【发布时间】: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