简体   繁体   中英

How to redirect a single page from https to http

I've redirect my website to https but I've need it to redirect a single page from https to http.

My rules to redirect to https are:

  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]

What rule I might use to redirect a single page to http?

I looked and here's an answer from a couple of years ago with a similar problem. This code works according to the comments:

Try with %{SERVER_PORT} (if default http port is still 80 and ssl port is 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]

Original question/answers at: 301 redirect HTTPS to HTTP for a single page

First your code will not catch none 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]

Make your code like this :

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

to exclude spacific page add this

 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]

Note: clear your browser cache and test it.

update:

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

Try this , it means catch any request contains https & your page then force into http

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM