How to always remove WWW from a url with mod_rewrite?

后端 未结 5 826
无人共我
无人共我 2020-12-24 09:21

I\'m using the following to try and remove WWW from the url:

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule (.*) http://example.com$1 [R=301]
         


        
5条回答
  •  醉酒成梦
    2020-12-24 10:13

    Try:

    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    

    And without mod_rewrite:

    
            ServerName www.example.com
            Redirect permanent / http://example.com/
    
    

    Virtual hosts can be used by completing the steps in the following URL: Setting Up A Virtual Host in Apache.

提交回复
热议问题