Make apache automatically strip off the www.?

后端 未结 6 1930
一生所求
一生所求 2021-01-03 08:56

For various reasons, such as cookies, SEO, and to keep things simple, I would like to make apache automatically redirect any requests for http://www.foobar.com/anything to h

6条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 09:10

    Use an .htaccess file with some mod_rewrite rules:

    RewriteEngine On
    RewriteRule ^www.SERVERNAME(.*) http://SERVERNAME$1 [L,QSA]
    

    I'm not sure I got the syntax right with the $1 there, but it's well documented. L sends a location: header to the browser, and QSA means Query String Append.

提交回复
热议问题