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

问题描述 投票:0回答:1

我想知道是否有可能将某些特定页面从非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。

但是似乎效果不佳

.htaccess mod-rewrite http-redirect
1个回答
0
投票

尝试这些:

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]

依此类推...

© www.soinside.com 2019 - 2024. All rights reserved.