繁体   English   中英

url重写-重定向到HTTP,除了一页

[英]url rewrite - redirect to HTTP except one page

我想使用SSL保护一页mysubdir/checkout.php 例如https://www.mywebsite.com/fr/checkout ,其中fr是语言代码。

所有其他页面应重定向回http。

这是我在.htaccess中所拥有的,但是它不起作用。

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/fr/checkout
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

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

##### Checkout #####
RewriteRule ^/(fr|en)/checkout/?$ mysubdir/checkout.php?lang=$1 [QSA]

但是,当我输入: https://www.mywebsite.com/fr/checkout : https://www.mywebsite.com/fr/checkout它会重定向到https://www.mywebsite.com/mysubdir/checkout.php?lang=fr 为什么?

有什么解决办法吗?

尝试:

RewriteEngine on
#redirect checkout.php from http to https
RewriteCond %{HTTPS} off
RewriteRule checkout\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
#redirect all requests except "checkout.php" from https to http
RewriteCond %{HTTPS} on
RewriteRule !checkout\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]

这只会将/checkout.php重定向到https。

您应该使用THE_REQUEST变量而不是REQUEST_URI因为上一次将REQUEST_URI更改为其他变量。

RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/fr/checkout
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /fr/checkout
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

##### Checkout #####
RewriteRule ^/?(fr|en)/checkout/?$ mysubdir/checkout.php?lang=$1 [QSA,L,NC]

测试时,请确保清除浏览器缓存。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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