Rewrite to www EXCEPT for one directory

I have the following in my nginx.conf to redirect to www. to deal with
Google duplicate issues.

server {
server_name example.com
listen 80;
location / {
rewrite ^(.*) http://www.example.com$1 permanent;
}
}

However, WordPress, which I’m installing in /blogs, is strongly
suggesting that we drop the www, at least for WordPress.

Is there a way to change the above config so it will do the “add www”
redirect EXCEPT for when the location is /blogs or below? (it’s a
multisite install so there’ll be /blogs/blog1, /blogs/blog2, etc)

On Thursday 06 September 2012 22:22:07 Ian E. wrote:

However, WordPress, which I’m installing in /blogs, is strongly
suggesting that we drop the www, at least for WordPress.

Is there a way to change the above config so it will do the “add www”
redirect EXCEPT for when the location is /blogs or below? (it’s a
multisite install so there’ll be /blogs/blog1, /blogs/blog2, etc)

server {
listen 80;
server_name example.com;

  location / {
      return 301 http://www.example.com$request_uri;
  }

  location /blogs {
      # configuration for WordPress
  }

}

wbr, Valentin V. Bartenev


http://nginx.org/donate