How to dynamically redirect www-based URLs to non-www URLs with multiple domains in same VirtualHost

后端 未结 3 927
轮回少年
轮回少年 2021-02-06 06:39

I\'ve got a VirtualHost that looks something like:



  ServerName  domain1.com
  ServerAlias www.domain1.com domain2.com www.domain2.com
         


        
3条回答
  •  北海茫月
    2021-02-06 07:43

    Your RewriteCond is a bit wonky. I'm surprised it does anything at all, since it would seem to be trying to match the host www.domain1.com against the pattern www\.www.domain1.com. These directives worked for me:

    # Redirect www to non-www
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^(.*)$ http://%1$1 [L,R=301]
    

提交回复
热议问题