apache redirect from non www to www

前端 未结 24 911
春和景丽
春和景丽 2020-11-22 06:34

I have a website that doesn\'t seem to redirect from non-www to www.

My Apache configuration is as follows:

RewriteEngine On
### re-direct t         


        
24条回答
  •  一向
    一向 (楼主)
    2020-11-22 07:01

    This works for me:

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

    I use the look-ahead pattern (?!www.domain.com) to exclude the www subdomain when redirecting all domains to the www subdomain in order to avoid an infinite redirect loop in Apache.

提交回复
热议问题