如何将单个页面从https重定向到http

时间:2017-10-08 10:54:15

标签: apache .htaccess redirect

我已将我的网站重定向到https,但我需要将其从https重定向到http。

我重定向到https的规则是:

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

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

我可能会使用什么规则将单个页面重定向到http?

2 个答案:

答案 0 :(得分:0)

我看了,这是几年前有类似问题的答案。此代码根据评论工作:

尝试使用%{SERVER_PORT}(如果默认http端口仍为80且ssl端口为443)

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{SERVER_PORT} 443
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

原始问题/答案:301 redirect HTTPS to HTTP for a single page

答案 1 :(得分:0)

首先,您的代码不会捕获任何wwww

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# the first two lines above will catch all http request so , nothing will 
# pass to the following 
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

让你的代码像这样:

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^   https://www.yoursite.com%{REQUEST_URI} [L,R=301]

排除空格页面添加此

 RewriteCond %{HTTPS} off [OR]
 RewriteCond %{HTTP_HOST} !^www\.
 RewriteCond %{REQUEST_URI} !^/your/path/to/pages$ 
 RewriteRule ^   https://www.yoursite.com%{REQUEST_URI} [L,R=301]

注意:清除浏览器缓存并对其进行测试。

  

更新

 RewriteCond %{HTTPS} on
 RewriteCond %{THE_REQUEST} my-page [NC] 
 RewriteRule ^   http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

试试这个,这意味着抓住任何包含https&的请求然后您的网页会强制进入http