gpt4 book ai didi

.htaccess - 仅针对某些特定页面将非 www/http 强制为 www/https

转载 作者:行者123 更新时间:2023-12-05 07:07:14 25 4
gpt4 key购买 nike

我想知道是否可以将某些特定页面从非 www/http 强制转换为 www/https,并保留其他非 www/http 页面。

例子

从非 www/http 到 www/https:

http://example.comhttps://www.example.com

但这些将保持非 www 和 http:

http://example.com/folder1/ *

http://example.com/folder2/ *

我尝试在 htaccess 文件中添加这个规则条件:

RewriteEngine On     

# Enable HTTPS and WWW for homepage
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteRule ^$ https://example.com/ [R=301,L]

# Disable HTTPS and WWW for all pages
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} on
RewriteRule . http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

然后它应该强制 https 和 www 只是主页,并将其他页面如 /folder1//folder2/ 留给 htpp 非 www。

但是好像不太好用

最佳答案

试试这些:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^folder1.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^folder2.*$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^folder1.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^folder2.*$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^folder1.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

等等……

关于.htaccess - 仅针对某些特定页面将非 www/http 强制为 www/https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62245318/

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