# Global www removal/redirect?

**URL:** <https://www.ruby-forum.com/t/global-www-removal-redirect/140043>\
**Category:** NGINX\
**Created:** [June 10, 2008, 11:08am UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043 "2008-06-10T11:08:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 11:08am UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/1 "2008-06-10T11:08:06Z")

</div>

## Is there a quick way to remove the redirect from [http://www](http://www).\* to http://\* without listing all the domains? I’m about to point a couple of hundred domains to a box running nginx, and need to remove all the www’s from the urls for the app to work.

_Phillip B Oldham_  
The Activity People  
removed\_email\_address@domain.invalid [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

_Policies_

This e-mail and its attachments are intended for the above named  
recipient(s) only and may be confidential. If they have come to you in  
error, please reply to this e-mail and highlight the error. No action  
should be taken regarding content, nor must you copy or show them to  
anyone.

This e-mail has been created in the knowledge that Internet e-mail is  
not a 100% secure communications medium, and we have taken steps to  
ensure that this e-mail and attachments are free from any virus. We must  
advise that in keeping with good computing practice the recipient should  
ensure they are completely virus free, and that you understand and  
observe the lack of security when e-mailing us.

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/2 "2008-06-10T12:13:07Z")

</div>

On Tue, Jun 10, 2008 at 09:59:55AM +0100, Phillip B Oldham wrote:

> Is there a quick way to remove the redirect from [http://www](http://www).\* to  
> http://\* without listing all the domains? I’m about to point a couple of  
> hundred domains to a box running nginx, and need to remove all the www’s  
> from the urls for the app to work.

server {  
server\_name www.\*;

```
   if ($http_host ~* ^www\.(.+)$) {
       set $h $1;
   }

   rewrite ^ http://$h$request_uri;

```

}

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 12:19pm UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/3 "2008-06-10T12:19:04Z")

</div>

Wonderful, thanks!

Igor S. wrote:

> ```
> server_name www.*;
> 
> if ($http_host ~* ^www\.(.+)$) {
> set $h $1;
> }
> 
> rewrite ^ http://$h$request_uri;
> 
> ```
> 
> }

–

_Phillip B Oldham_  
The Activity People  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

_Policies_

This e-mail and its attachments are intended for the above named  
recipient(s) only and may be confidential. If they have come to you in  
error, please reply to this e-mail and highlight the error. No action  
should be taken regarding content, nor must you copy or show them to  
anyone.

This e-mail has been created in the knowledge that Internet e-mail is  
not a 100% secure communications medium, and we have taken steps to  
ensure that this e-mail and attachments are free from any virus. We must  
advise that in keeping with good computing practice the recipient should  
ensure they are completely virus free, and that you understand and  
observe the lack of security when e-mailing us.

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 12:29pm UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/4 "2008-06-10T12:29:39Z")

</div>

Thanks Igor,

I’ll keep this email under my arm for the time being. In the near  
future I will certainly have to use it also, and moreover it helps me  
understand nginx rewrite module.

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 1:16pm UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/5 "2008-06-10T13:16:53Z")

</div>

On Tue, Jun 10, 2008 at 05:48:58PM +0700, Denis F. Latypoff wrote:

> by the way, Igor, this rule will rewrite
> 
> [http://www.domain.com/path?arg=value](http://www.domain.com/path?arg=value)  
> to  
> [http://domain.com/path?arg=value?arg=value](http://domain.com/path?arg=value?arg=value)
> 
> as well as the ‘rewrite ^(.\*) http://$h$1;’
> 
> just found it.

Then

- 

```
  rewrite ^ http://$h$request_uri;

```

- 

```
  rewrite ^ http://$h$request_uri?;

```

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/6 "2008-06-10T13:47:36Z")

</div>

Hello Igor,

Tuesday, June 10, 2008, 6:05:17 PM, you wrote:

> On Tue, Jun 10, 2008 at 05:48:58PM +0700, Denis F. Latypoff wrote:

> > by the way, Igor, this rule will rewrite
> > 
> > [http://www.domain.com/path?arg=value](http://www.domain.com/path?arg=value)  
> > to  
> > [http://domain.com/path?arg=value?arg=value](http://domain.com/path?arg=value?arg=value)
> > 
> > as well as the ‘rewrite ^(.\*) http://$h$1;’
> > 
> > just found it.

> Then

> - 
> 
> ```
> rewrite ^ http://$h$request_uri;
> 
> ```
> 
> - 
> 
> ```
> rewrite ^ http://$h$request_uri?;
> 
> ```

ok, that did the trick, thanks 😉

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [June 10, 2008, 12:57pm UTC](https://www.ruby-forum.com/t/global-www-removal-redirect/140043/7 "2008-06-10T12:57:24Z")

</div>

Hello Igor,

Tuesday, June 10, 2008, 5:02:38 PM, you wrote:

> On Tue, Jun 10, 2008 at 09:59:55AM +0100, Phillip B Oldham wrote:

> > Is there a quick way to remove the redirect from [http://www](http://www).\* to  
> > http://\* without listing all the domains? I’m about to point a couple of  
> > hundred domains to a box running nginx, and need to remove all the www’s  
> > from the urls for the app to work.

> server {  
> server\_name www.\*;

> ```
> if ($http_host ~* ^www\.(.+)$) {
> set $h $1;
> }
> 
> ```

> ```
> rewrite ^ http://$h$request_uri;
> 
> ```
> 
> }

by the way, Igor, this rule will rewrite

[http://www.domain.com/path?arg=value](http://www.domain.com/path?arg=value)  
to  
[http://domain.com/path?arg=value?arg=value](http://domain.com/path?arg=value?arg=value)

as well as the ‘rewrite ^(.\*) http://$h$1;’

just found it.
