【问题标题】:redirection all https requests to http将所有 https 请求重定向到 http
【发布时间】:2014-06-30 20:30:16
【问题描述】:

这里有个小问题,在将我的网站更改为 CMS 之前,我遇到了将所有 https:// 请求重定向到 http:// 的问题。

我的 .htaccess 中有以下内容,它正在做这一切

 RewriteCond %{SERVER_PORT} ^443$
 RewriteRule ^(.*)$ http://www.mysite.net/$1 [L,R=301]

但在将其更改为需要不同设置的 CMS 后,我无法再使用上述代码,因为它并没有按照最初的预期进行。

这是我在 .htaccess 的当前设置

 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-l
 RewriteRule ^(.*)$ index.php/$1 [QSA,L,NC]
 RewriteCond %{HTTP_HOST} !^(www\.)mysite\.net$ [NC]
 RewriteRule ^(.*)$ http://www.mysite.net/$1 [L,R=301]
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.net/.*$ [NC]
 RewriteRule \.(gif|jpg|png|tif|js|css|xls|xlsx|zip|rar|pdf|ods|ots)$ - [F]

您能否告诉我如何正确地完成这一切,因为我真的不想因为这个问题而将所有网站内容加倍,而是宁愿将其全部重定向到一个一致的协议。

提前致谢

【问题讨论】:

    标签: apache .htaccess http mod-rewrite https


    【解决方案1】:

    让你的 .htaccess 像这样:

     RewriteEngine On
     RewriteBase /
    
     RewriteCond %{HTTP_HOST} !^www\. [NC]
     RewriteRule ^ http://www.mysite.net%{REQUEST_URI} [L,R=301,NE]
    
     RewriteCond %{HTTPS} on [OR]
     RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
     RewriteCond %{SERVER_PORT} ^443$
     RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
     RewriteCond %{HTTP_REFERER} !^$
     RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.net/.*$ [NC]
     RewriteRule \.(gif|jpg|png|tif|js|css|xls|xlsx|zip|rar|pdf|ods|ots)$ - [F,NC]
    
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-l
     RewriteRule ^(.+)$ index.php/$1 [L]
    

    【讨论】:

    • 在 Firebug 中试试这个,看看你是否得到 301。使用此代码<?php phpinfo(); ?> 进一步创建一个名为info.php 的文件,然后打开https://mysite.net/info.php 以检查它的DOCUMENT_ROOT 值是多少。
    • 文档根值是/var/www/vhosts/mysite.net/httpdocs
    • 和http网站的DOCUMENT_ROOT完全一样吗?你在 Firebug 中得到 301 了吗?
    • 我尝试过使用 firebug,但它不是 301ing,而是在 css 文件上给出 403,当我尝试使用 https:// 时,它会无休止地重定向
    • 与 DOCUMENT_ROOT 完全相同
    猜你喜欢
    • 2017-04-30
    • 2011-05-04
    • 2016-11-17
    • 1970-01-01
    • 2018-05-05
    • 2016-10-23
    • 2018-02-22
    相关资源
    最近更新 更多