dongyao5186 2015-07-21 08:12
浏览 57

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.

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

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]
</IfModule>

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 ^(.*)$ http://foobar.example.com/$1 [L,R=301]

Here is apache config for http requests: /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>

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.

  • 写回答

1条回答 默认 最新

  • dsjhejw3232 2015-07-24 06:50
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题