繁体   English   中英

htaccess:除特定域外,所有域均使用https

[英]Htaccess : https for all except specific domains

我有以下规则将所有请求重定向到https://www.mainsite.com

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

现在,我想将http://another-domain.com重定向到一个特定的文件夹(博客),但没有https因此我添加了它。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?another-domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?another-domain$ [NC]
RewriteRule ^(/)?$ blog/index.php [L]

即使http://another-domain.com仍然重定向到https://www.mainsite.com

有这种方式:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?!(www\.)?another-domain\.com$)(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L,NE]

RewriteCond %{HTTP_HOST} ^(www\.)?another-domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!blog/).+)$ blog/$1 [L]

RewriteCond %{HTTP_HOST} ^(www\.)?another-domain\.com$ [NC]
RewriteRule ^/?$ blog/index.php [L]   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM