gpt4 book ai didi

performance - 带有 .htaccess 的选择性 SSL 强制 http ://or https://

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

出于性能方面的原因,我正在尝试更有选择性地选择使用 SSL 的页面/请求。我想使用 htaccess 仅针对所需页面重定向到 https:// 并针对其他所有页面重定向回 http:// .这是我的:

RewriteEngine On

# force https
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)/(abc|xyz)(.*)$ https://%{HTTP_HOST}/$1/$2 [R=301,NC,L]

RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_REFERER} !^https(.*)/(abc|xyz)(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^(.*)/(abc|xyz)(.*)$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ initialize.php [QSA,L]

安全请求是abcxyz。问题是,如果请求 http://example.com/abc,它会重定向到 http://example.com/initialize.php。非安全页面按预期工作。

最佳答案

因为这是一个有几年历史的问题,我很确定它已经解决了,但对于可能遇到这个问题的人来说,我认为这样的事情是可行的。很难知道上面的 abcxyz 是什么,但我假设它们是 URI 路径的一部分。

# Forward some URI's to HTTPS.
RewriteCond %{HTTPS} =off
RewriteCond $1 (abc|xyz) [NC]
RewriteRule ^(.+)$ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,S=1,L]

# Forward rest of the request to HTTP
RewriteCond %{HTTPS} =on
RewriteCond $1 !(abc|xyz) [NC]
RewriteRule ^(.+)$ http://%{HTTP_HOST}%{REQUEST_URI} [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ initialize.php [QSA,L]

此外,解决此问题的提示是启用 mod_rewrite logging .

关于performance - 带有 .htaccess 的选择性 SSL 强制 http ://or https://,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3017851/

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