繁体   English   中英

仅通过几页通过htaccess将http重定向到https

[英]redirect http to https via htaccess only for few pages

我有启用SSL的网站。

问题:我只想将http重定向到https的检出页面。

我正在使用以下代码进行重定向:

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

但是它将所有http重定向到htaccess。

我想要的是:我想对htaceess设置一些条件,以便仅结帐页面将重定向到https,否则将不进行重定向。

下面的代码解决了我的问题(当我在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 / etc也将如上所述重定向

并且其他请求将被重定向到https例如

abc.123 / test变为https://abc.123/test

您必须捕获端口80上的结帐页面请求

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

暂无
暂无

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

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