将所有https请求重定向到http

时间:2014-05-13 08:49:01

标签: apache .htaccess http mod-rewrite https

此处存在小问题,在将我的网站更改为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]

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

提前致谢

1 个答案:

答案 0 :(得分: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]