强制HTTPS到一个目录 - 删除WWW

时间:2013-08-08 08:48:03

标签: .htaccess http https

我有一个小问题,这是我用来强制https到结帐目录,只是一个预防措施,但问题是,一旦你回到它将URL插入URL的主页面。< / p>

这是一个问题,因为其余的视线不使用www,任何人都可以建议如何添加此删除/保留www

# force https for all URLs in /checkout
RewriteCond %{HTTPS} =off
RewriteRule ^x9 https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# force http for all other URLs that are not in /checkout
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/x9
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

修改

如果你说它不是上面那部分。此问题仅在添加上述代码后才开始,我以前从未遇到此问题,下面的代码已经在我的网站上停留了好几个月。

 #Take off index.html
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

1 个答案:

答案 0 :(得分:1)

在这种情况下,请保留你的.htaccess:

#Take off index.html
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]

# force https for all URLs in /checkout
RewriteCond %{HTTPS} =off
RewriteRule ^x9 https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# force http for all other URLs that are not in /checkout
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/x9
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]