2011-03-28 100 views
0

我有作为SSL的网站。只通过htaccess将http重定向到https只有少数几个网页

问题:我希望http将仅重定向到https用于结帐页面。

我使用下面的代码重定向:

RewriteEngine On 
RewriteCond %{HTTPS} !on 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

,但它会将所有的HTTP到htaccess的。

我想要什么:我想在htaceess上添加一些条件,以便只有结帐页面将重定向到https,否则不会进行重定向。

回答

0

,你必须赶上你结帐页面请求到来的80端口

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} your-checkout-uri-pattern 
RewriteRule ^(.*)$ https://your-sslized-site/$1 [R,L] 
0

下面的代码解决我的问题(当我在API使用它)。它也可能解决你的问题。试一试。

在这里你去,

# For redirecting HTTP to HTTPS, comments are line by line 
# below line checks for https flag 
RewriteCond %{HTTPS} off 
# below line excludes the mentioned URIs from redirection 
RewriteCond %{REQUEST_URI} !^/(myFirstUri|mySecondUri|myThirdUri) 
# below line redirects all other URIs except the ones that are mentioned above 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

所以,什么在这里发生的是,我所有的请求都将被重新定向到https除了下面的人

abc.123/myFirstUri将成为http://abc.123/myFirstUri

abc.123/myFirstUri/QW /等也将被重新定向以上

如所述个

而其他请求都将被重新定向到https e.g

abc.123 /测试变得https://abc.123/test

相关问题