我想使用.htaccess从https上的url中删除www

时间:2012-03-01 05:03:30

标签: .htaccess url-rewriting

我想通过.htaccess从https网址中删除www。 例如

我想改变

https://www.example.com/至https://example.com/

我尝试了很多规则

RewriteCond %{HTTPS} =on
RewriteCond %{HTTP_HOST}  ^www\.example\.com$ [NC]  
RewriteRule ^(.*)$    https://example.come/$1 [L]

RewriteCond %{SERVER_PORT} ^443
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule (.*) https://example.com$1 [L,R,QSA]

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

但没有任何效果。请帮帮我

2 个答案:

答案 0 :(得分:0)

尝试:


RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI} [L,R=301]

答案 1 :(得分:0)

请确保您使用X-Forwarding然后试试这个:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://example.com/$1 [R,L]