2016-07-08 77 views
0

我希望使用SSL来保护一个页面mysubdir/checkout.php。 例如https://www.mywebsite.com/fr/checkout,其中fr是语言代码。网址重写 - 重定向到HTTP,除了一页以外

所有其他页面应该重定向回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/mysubdir/checkout.php?lang=fr。为什么?

对此的任何解决方案?

回答

0

尝试:

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。

+0

但在我的情况下,checkout.php也被重写为/ fr/checkout。 – sc1013

+0

问题到底是什么?有没有其他规则或htaccess? – starkeen

0

自上次更改REQUEST_URI以来,您应该使用THE_REQUEST变量而不是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] 

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

相关问题