[英]Redirect some page to http and some page to https
I have used this code for redirecting to https: 我已使用此代码重定向到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. 但是我需要使用http而不是https的某些页面。
Example: I need this url: http://www.mysite.com/test/contact.php
范例:我需要这个网址:
http://www.mysite.com/test/contact.php
: 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 您也可以在PHP中使用一些条件语句和标头来实现,例如
if(something) {
header("Location: https://www.example.com/");
}
Be sure not to output anything before header() 确保在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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.