apache redirect from non www to www

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

    Using the rewrite engine is a pretty heavyweight way to solve this problem. Here is a simpler solution:

    
        ServerName example.com
        Redirect permanent / http://www.example.com/
    
    
    
        ServerName www.example.com
        # real server configuration
    
    

    And then you'll have another section with ServerName www.example.com for your real server configuration. Apache automatically preserves anything after the / when using the Redirect directive, which is a common misconception about why this method won't work (when in fact it does).

提交回复
热议问题