用于https url的htaccess规范化(http:// www)

时间:2016-08-12 05:32:57

标签: .htaccess url canonicalization

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
RewriteCond %{HTTPS} off 

RewriteCond %{HTTPS_HOST} !^www.website.com$ [NC]
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]

我用它来重定向:

我尝试将此代码更改为https,但它仍无法正常工作。我有什么不对的吗?

2 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS_HOST} !^www.website.com$ [NC]
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]

使用[OR]

答案 1 :(得分:0)

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

这段代码对我有用。谢谢!