仅针对少数页面通过 htaccess 将 http 重定向到 https

发布于 2024-10-26 21:18:17 字数 337 浏览 2 评论 0原文

我有启用 SSL 的网站。

问题:我希望 http 仅针对结帐页面重定向到 https。

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

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

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

我想要的:我想在 htaceess 上设置一些条件,以便只有结账页面才会重定向到 https,否则不会进行重定向。

I have as SSL enabled website.

Issue : I want that http will redirect to https only for checkout pages.

I am using following code for redirection:

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

but it redirects all http to htaccess.

What I Want : I want to put some condition on htaceess so that only checkout pages will redirect to https otherwise no redirection will be done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠栀 2024-11-02 21:18:18

您必须捕获来自端口 80 的结账页面请求

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

you have to catch the requests for your checkout pages coming on port 80

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} your-checkout-uri-pattern
RewriteRule ^(.*)$ https://your-sslized-site/$1 [R,L]
帅气称霸 2024-11-02 21:18:18

下面的代码解决了我的问题(当我在 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

The below piece of code solves my problem (when i was using it in api). It might also slove your problem. Give it a try.

Here you go,

# 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} 

So, whats happening here is that all my requests will be re-directed to https except the below ones

abc.123/myFirstUri will become http://abc.123/myFirstUri

abc.123/myFirstUri/qw/etc will also be re-directed as stated above

And the others requests will be re-directed to https e.g

abc.123/test becomes https://abc.123/test

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文