gpt4 book ai didi

mod-rewrite - mod_rewrite : 2 files should always be SSL, 其余的总是 HTTP

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:54 25 4
gpt4 key购买 nike

我想确保我的应用程序中的少量 URL 始终通过 SSL 提供服务;其余部分应始终通过 HTTP 提供。

我当前的 mod_rewrite 规则集是这样的:

RewriteCond %{HTTPS}            off
RewriteRule ^/?account.html$ https://example.com/account.html [L]
RewriteRule ^/?checkout.html$ https://example.com/checkout.html [L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !/account.html$
RewriteCond %{REQUEST_URI} !/checkout.html$
RewriteRule (.*) http://example.com/$1 [L]

每个 RewriteCond 中的第一个文件工作正常(本例中为 account.html)。第二个文件不起作用 - 服务器正在“以一种永远不会完成的方式重定向”。

关于如何使这项工作有任何想法吗?在生产环境中,将有超过 2 个仅限 SSL 的 URL,可能有 7 - 10 个。

谢谢

最佳答案

您必须使用 R 标志来重定向 url

RewriteEngine On

# redirect account.html or checkout.html (if http) to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/(account|checkout)\.html$ [NC]
RewriteRule ^ https://%{HTTP_HOST}/%1.html [R,L]

# redirect other urls (if https) to http
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/(account|checkout)\.html$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R,L]

注意:我使用了 R 标志,它默认执行 302 重定向。当 [R=301,L] 正常工作时,请随意将 [R,L] 替换为 [R,L](301 重定向是一个永久 重定向并且是由浏览器缓存)

关于mod-rewrite - mod_rewrite : 2 files should always be SSL, 其余的总是 HTTP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25689149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com