apache redirect from non www to www

前端 未结 24 1223
春和景丽
春和景丽 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 06:52

    This is similar to many of the other suggestions with a couple enhancements:

    • No need to hardcode the domain (works with vhosts that accept multiple domains or between environments)
    • Preserves the scheme (http/https) and ignores the effects of previous %{REQUEST_URI} rules.
    • The path portion not affected by previous RewriteRules like %{REQUEST_URI} is.

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

提交回复
热议问题