apache redirect from non www to www

前端 未结 24 937
春和景丽
春和景丽 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:00

    Do not always use Redirect permanent (or why it may cause issues in future)

    If there is a chance that you will add subdomains later, do not use redirect permanent.

    Because if a client has used a subdomain that wasn't registred as VirtualHost he may also never reach this subdomain even when it is registred later.

    redirect permanent sends an HTTP 301 Moved Permanently to the client (browser) and a lot of them cache this response for ever (until cache is cleared [manually]). So using that subdomain will always autoredirect to www.*** without requesting the server again.

    see How long do browsers cache HTTP 301s?

    So just use Redirect

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

    Apache.org - When not to use mod_rewrite

    Apache.org - Canonical Hostnames

提交回复
热议问题