将某个页面重定向到http,将某个网页重定向到https


Redirect some page to http and some page to https

我使用此代码重定向到https:

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

但我需要一些使用http而不是https的页面。

示例:我需要这个网址:http://www.mysite.com/test/contact.php

尝试:


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]

您也可以在PHP中使用一些条件语句和类似的标头来实现这一点

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

请确保在header()之前不要输出任何内容

这是条件

   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]