问题
I have a multidomain site,
Which means depending on the domain a version of content is displayed,
So for now I have domains chiname.com
and greatwall.com
When a user lands on chiname.com
gets redirected to https://www.greatwall.com
except for two folder /landing
and /marketing
which stays on chiname.com
but wanted it to be on the https
version of chiname.com
.
I tried adding a rewriteRule, but doesn't work for me
RewriteEngine On
RewriteCond %{HTTP_HOST} ^chiname.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing)
RewriteRule ^(landing/.*)$ https://www.chiname.com/$1 [R=301,L]
RewriteRule ^(marketing/.*)$ https://www.chiname.com/$1 [R=301,L]
RewriteRule ^(.*)$ https://www.greatwall.com/$1 [R=301,L]
回答1:
You may use these 2 redirect rules:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?chiname\.com$ [NC]
RewriteRule ^(landing|marketing) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC,NE]
RewriteCond %{HTTP_HOST} ^(?:www\.)?chiname\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/(landing|marketing) [NC]
RewriteRule ^ https://www.greatwall.com%{REQUEST_URI} [R=301,L,NC,NE]
Make sure to use a new browser for testing.
来源:https://stackoverflow.com/questions/54809486/htaccess-redirect-excluded-subfolder-to-https-version-of-domain-and-everything