简体   繁体   中英

Redirect some page to http and some page to https

I have used this code for redirecting to https:

RewriteEngine on
#Options +FollowSymlinks
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*) https://www.mysite.com/test/$1 [R,L]

but I need some pages using http not to https.

Example: I need this url: http://www.mysite.com/test/contact.php

Try:


RewriteEngine on
#Options +FollowSymlinks
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*) https://www.mysite.com/test/$1 [R,L]

RewriteCond %{SCRIPT_FILENAME} \/contact\.php [NC]
RewriteRule ^(contact.php)$ http://%{HTTP_HOST}/$1 [R,L]

You can do it in PHP as well with some conditional statements and header something like

if(something) {
   header("Location: https://www.example.com/");
} 

Be sure not to output anything before header()

That is the condition

   RewriteCond %{HTTPS} off

    RewriteCond %{SCRIPT_FILENAME} !\/contact\.php [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/test/$1 [R,L]

    RewriteCond %{HTTPS} on

    RewriteCond %{SCRIPT_FILENAME} \/contact\.php [NC]
    RewriteRule ^(.*)$ http://%{HTTP_HOST}/test/$1 [R,L]

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