apache redirect from non www to www

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

    If using the above solution of two blocks with different ServerNames...

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

    ... then you must set NameVirtualHost On as well.

    If you don't do this, Apache doesn't allow itself to use the different ServerNames to distinguish the blocks, so you get this error message:

    [warn] _default_ VirtualHost overlap on port 80, the first has precedence
    

    ...and either no redirection happens, or you have an infinite redirection loop, depending on which block you put first.

提交回复
热议问题