gpt4 book ai didi

.htaccess - 从 http 到 https 页面的永久重定向

转载 作者:行者123 更新时间:2023-12-04 16:23:48 26 4
gpt4 key购买 nike

当我尝试使用 .htaccess 创建从 HTTP 页面重定向到 HTTPS 页面(仅针对特定页面)的规则时,我收到了循环重定向。我哪里错了?

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^(/doctor) [NC, OR]
RewriteCond %{REQUEST_URI} ^(/client)
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^(/doctor) [NC, OR]
RewriteCond %{REQUEST_URI} !^(/client)
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]

最佳答案

强制 https 用于特定文件夹的使用

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]

供整个网站使用
RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

对于您可以使用的特定页面
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} ^/doctor/?.*$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]

检查服务器端口是否不同于 443(安全连接的标准),以确保我们将仅重定向非安全连接

将页面 secure.php 重定向到安全域,发送 301 响应状态,附加所有查询字符串并标记为最后一条规则,因此不会解析低于此的任何规则(因为这是重定向,我们不想采取任何其他 Action )

这是我发现的不使用 .htaccess 的解决方案 here
    <?php

//assuming you site structure like www.domain.com/p=doctor

$redirectlist = array('doctor','nurse','anyother');

if (in_array($_GET['p'], $redirectlist) && strtolower($_SERVER['HTTPS']) != 'on') {
exit(header("location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}"));
}

?>

关于.htaccess - 从 http 到 https 页面的永久重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4933001/

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