gpt4 book ai didi

apache - 使用 htaccess 将 HTTPS 重定向到单个 PHP 文件

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:08 28 4
gpt4 key购买 nike

我正在尝试重定向 https://demo.aurazoscript.com/surf.php?id=15http://demo.aurazoscript.com/surf.php?id=15 .我在 .htaccess 中尝试了以下操作,但这不起作用。它关闭了我不想要的整个网站的强制 HTTPS 重定向。我只想为那个单页 surf.php 关闭它。

我在 .htaccess 中尝试过

# FORCE HTTPS
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} \/(surf.php)
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

# DISABLE HTTPS
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !\/(surf.php) [NC]
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

我正在使用 CloudFlare 的灵活 SSL。

最佳答案

我想你做的是相反的方式,在 RewriteEngine On 之后的 .htaccess 文件的开头试试这个:

RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
RewriteCond %{HTTPS} on
RewriteRule ^surf\.php http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule !^surf\.php https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

注意:清除浏览器缓存然后测试。

关于apache - 使用 htaccess 将 HTTPS 重定向到单个 PHP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49679828/

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