# Rewrite to www EXCEPT for one directory

**URL:** <https://www.ruby-forum.com/t/rewrite-to-www-except-for-one-directory/222706>\
**Category:** NGINX\
**Created:** [September 6, 2012, 8:22pm UTC](https://www.ruby-forum.com/t/rewrite-to-www-except-for-one-directory/222706 "2012-09-06T20:22:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [September 6, 2012, 8:22pm UTC](https://www.ruby-forum.com/t/rewrite-to-www-except-for-one-directory/222706/1 "2012-09-06T20:22:36Z")

</div>

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

server {  
server\_name [example.com](http://example.com)  
listen 80;  
location / {  
rewrite ^(.\*) [http://www.example.com$1](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)

---

<div class="post-metadata">

**Author:** ![peterpiper](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/3e96dc/32.png) [@peterpiper](https://www.ruby-forum.com/u/peterpiper)\
**Post date:** [September 6, 2012, 8:38pm UTC](https://www.ruby-forum.com/t/rewrite-to-www-except-for-one-directory/222706/2 "2012-09-06T20:38:57Z")

</div>

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](http://example.com);

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

  location /blogs {
      # configuration for WordPress
  }

```

}

wbr, Valentin V. Bartenev

–  
[http://nginx.org/donate](http://nginx.org/donate)

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.
