0

I've searched everywhere and although there are 1000s of examples of how to strip a leading www from a URL using NGINX rewrite rules, I've yet to find an example of how to strip the leading 'www' from a vanity url.

For example, convert 'www.fred.mysite.com' to 'fred.mysite.com'

Can you share an example of how this should work in an nginx rewrite rule?

4

1 回答 1

0

最简单的方法是使用第二个服务器块,如下所示:

server {
  listen [::]:80; listen 80;
  server_name www.fred.mysite.com;
  return 301 $scheme://fred.mysite.com$request_uri;
} 

server {
  listen [::]:80; listen 80;
  server_name fred.mysite.com;

  #your site setup goes here
}

尽管您可能想使用“server_name *.fred.mysite.com;” 在第一个服务器块中只是为了捕获所有可能的额外前缀,包括拼写错误

于 2012-10-02T09:31:20.287 回答