Remove WWW prefix from your website

前端 未结 9 667
情歌与酒
情歌与酒 2020-12-28 19:24

How does Stack Overflow (and other web sites) remove the \'www\' prefix when it\'s entered as part of a URL?

Is it a redirect, a rewrite or something else entirely?<

9条回答
  •  旧巷少年郎
    2020-12-28 20:02

    An easy way to do this is using the Apache "Redirect" directive:

    
        ServerName www.example.com
        Redirect permanent / http://example.com/
    
    
    
        ServerName example.com
        # remainder of server configuration goes here
    
    

    The Redirect directive automatically preserves anything following the / in the URL. I find this method easier to read and understand than the Rewrite method.

提交回复
热议问题