dpn4073 2016-03-14 00:11
浏览 91

Apache(htaccess)重定向循环http https

We are experiencing a redirect loop on Wordpress homepage and I have no idea where does it come from, we switched the URL to http://www to https://.

Here is the htaccess file:

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

http://scrybs.com is redirecting to http://www.scrybs.com and http://www.scrybs.com is causing a redirect loop...

I tried to deactivate all plugins, remove htaccess file, none of those worked.

Thanks a lot.

  • 写回答

1条回答 默认 最新

  • donglefu6195 2016-03-14 00:41
    关注

    Don't use RewriteRules for the HTTP to HTTPS redirect. Change it to have the HTTP (port 80) virtual host redirect to the HTTPS (port 443) virtual host and put all your configuration in the HTTPS (port 443) configuration.

    <VirtualHost *:80>
        ServerName www.example.com
        Redirect "/" "https://www.example.com/"
    </VirtualHost >
    
    <VirtualHost *:443>
        ServerName www.example.com
        # ... SSL configuration goes here
    </VirtualHost >
    

    Ref: https://httpd.apache.org/docs/2.4/rewrite/avoid.html

    Then, remove these lines:

    RewriteCond %{HTTP_HOST} ^www\.(.*)
    RewriteRule ^.*$ https://%1/$1 [R=301,L]
    
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    You may want to restore the www configuration, but without the HTTPS update.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)