2015-07-21 08:12

WordPress https重定向循环

I'm trying to setup WordPress blog to subfolder on domain using SSL without success. If the blog .htaccess is set to redirect all HTTP to HTTPS then it results redirect loop. If .htaccess is not set to redirect all HTTP to HTTPS then blog is not showing properly as browser is blocking all HTTP requests as SSL is in use, also wp logins are failing in this case.

- Fresh WordPress installation
- Domain is using SSL
- WP installed on subfolder
- HTTPS set to WP's home and site URL in database

Here is the blog folder .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]

Here is the main domain .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 ^(.*)$$1 [L,R=301]

Here is apache config for http requests: /etc/apache2/sites-available/000-default.conf

<VirtualHost *:80>
   ServerAlias *
   ServerSignature Off
   RewriteEngine on
   RewriteCond %{HTTPS} !=on
   RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [NE,R,L]

Any help and ideas what to check would be highly appreciated.

UPDATE: I have manually replaced all HTTP urls with HTTPS in the WP database, the only occurrences were sample page and post urls, but this didn't help to resolve the problem.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dsjhejw3232 dsjhejw3232 6年前

    I was able to resolve the problem by adding $_SERVER['HTTPS']='on'; into wp-config.php. I don't know why $_SERVER['HTTPS'] is not set properly by the system, but I guess its somehow related to Apache/SSL configurations.

    Without setting $_SERVER['HTTPS']='on' WP was not able to detect HTTPS and was loading content over HTTP which with .htaccess redirects caused redirect loop.

    点赞 评论 复制链接分享