gpt4 book ai didi

php - apache htaccess 不添加 https ://www to any page except inside. php

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

我们有一个客户的网站,目前在我们的开发服务器上。我们在格式化 .htaccess 文件时遇到了一些问题。目前,htaccess 文件仅在 inside.php 上导致重定向到 https://www.。我们的目标是让每个页面都重定向到使用 https://www.。我们目前在每个页面都包含的 header.php 文件中使用基本 url 设置。不确定是否有更好的方法来完成我们正在尝试做的事情,但如果有任何帮助,我们将不胜感激。

这是我们的 .htaccess 文件的当前内容。

RewriteEngine on

#enables you to access PHP files with HTML extension
AddType application/x-httpd-ea-php70 .html .htm

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]

#forces https://
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

#forces www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


RewriteRule ^physicians(/((([a-zA-Z0-9_-]+)/?)*))?$ physicians.php?link=$2 [NC,L]

RewriteRule ^((([a-zA-Z0-9_-]+)/?)*)$ inside.php?page=$1


ErrorDocument 404 /inside.php

最佳答案

当请求是针对真实文件、目录或符号链接(symbolic link)时,您提前退出

RewriteRule ^ - [L]

仅在 这条规则之后,请求被重定向到 https://www.。要将所有 请求重定向到https://www.,请将规则移到开头,例如

#forces www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]

#forces https://
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

# all other rules come here
# ...

我还将非 www 部分移到了前面,否则如果原始请求是针对 http://example.com 的话,您将有两个重定向。

从不使用 R=301 进行测试!

关于php - apache htaccess 不添加 https ://www to any page except inside. php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43739860/

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