# Remove URI string?

**URL:** <https://www.ruby-forum.com/t/remove-uri-string/229354>\
**Category:** NGINX\
**Created:** [January 9, 2013, 5:36pm UTC](https://www.ruby-forum.com/t/remove-uri-string/229354 "2013-01-09T17:36:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 9, 2013, 5:36pm UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/1 "2013-01-09T17:36:29Z")

</div>

Hello all -

I would like to strip all request\_uri strings for a group of server  
names  
and serve up an index page.  
Example:

Client requests [http://host1.domain.com/blah](http://host1.domain.com/blah), nginx will direct client  
to  
[http://host1.domain.com](http://host1.domain.com) and serve the index page. Same scenario for  
host2 -  
I would like nginx to direct client to [http://host2.domain.com](http://host2.domain.com) and serve  
the  
same index page.

Would the below work?

server {  
server\_name [host1.domain.com](http://host1.domain.com) [host2.domain.com](http://host2.domain.com);  
rewrite ^ http://$server\_name;  
root /path/to/document/root;  
index index.html;  
}

Thank you!

Posted at Nginx Forum:

> **[Remove URI string?](https://forum.nginx.org/read.php?2,234822,234822#msg-234822)**
>
> Hello all - I would like to strip all request\_uri strings for a group of server names and serve up an index page. Example: Client requests http://host1.domain.com/blah, nginx will direct client to http://host1.domain.com and serve the index page....

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 9, 2013, 5:44pm UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/2 "2013-01-09T17:44:05Z")

</div>

On 9 January 2013 16:35, daveyfx [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Would the below work?
> 
> server {  
> server\_name [host1.domain.com](http://host1.domain.com) [host2.domain.com](http://host2.domain.com);  
> rewrite ^ http://$server\_name;  
> root /path/to/document/root;  
> index index.html;  
> }

Have you tried it? How about doing that?

It looks ok to me, but running it on a test machine will probably tell  
you all you need to know …

## Jonathan

Jonathan M. // Oxford, London, UK

> **[Jonathan Matthews :: Words Typed, Great Rates For Cash](https://www.jpluscplusm.com)**

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 10, 2013, 5:36am UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/3 "2013-01-10T05:36:18Z")

</div>

I gave it a try and it did not work out. My access log repeated the  
following entry ~ 20 times.

[09/Jan/2013:23:31:47 -0500] “GET / HTTP/1.1” 302 160 “-” “Mozilla/5.0  
(Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0”

Firefox kindly informed me that “The page isn’t redirecting properly”  
I’m  
guessing it’s getting caught in an infinite redirect.

Is there anything else I can try?

Thank you!

Posted at Nginx Forum:

> **[Re: Remove URI string?](https://forum.nginx.org/read.php?2,234822,234868#msg-234868)**
>
> Hello all - I would like to strip all request\_uri strings for a group of server names and serve up an index page. Example: Client requests http://host1.domain.com/blah, nginx will direct client to http://host1.domain.com and serve the index page....

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 10, 2013, 5:38am UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/4 "2013-01-10T05:38:39Z")

</div>

On Thu, Jan 10, 2013 at 11:35 AM, daveyfx [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

location = / {  
index index.html;  
}  
location / {  
return 302 /;  
}

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 10, 2013, 3:43pm UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/5 "2013-01-10T15:43:28Z")

</div>

On Thu, Jan 10, 2013 at 9:29 PM, daveyfx [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > 
> > 
> > location / {  
> > return 302 /;  
> > }
> 
> Thank you for the suggestion Edho. Unfortunately this still gave me a  
> redirect loop.

clear your browser’s history. Actually, don’t use browser for testing  
redirect. Use curl.

And make sure you’ve removed all other rewrites.

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 10, 2013, 3:29pm UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/6 "2013-01-10T15:29:26Z")

</div>

## Edho A. Wrote:

> properly" I’m  
> }

Thank you for the suggestion Edho. Unfortunately this still gave me a  
redirect loop.

> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,234822,234906#msg-234906](http://forum.nginx.org/read.php?2,234822,234906#msg-234906)

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 10, 2013, 5:13pm UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/7 "2013-01-10T17:13:53Z")

</div>

On Thu, Jan 10, 2013 at 11:37:44AM +0700, Edho A. wrote:

> On Thu, Jan 10, 2013 at 11:35 AM, daveyfx [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

Hi there,

> > I gave it a try and it did not work out. My access log repeated the  
> > following entry ~ 20 times.

As mentioned:

curl -i [http://server/something](http://server/something)  
curl -i [http://server/](http://server/)

are much friendlier for testing with. You’ll see exactly what the server  
sends back.

> location = / {  
> index index.html;  
> }  
> location / {  
> return 302 /;  
> }

With that configuration, a request for / will lead to an internal  
rewrite to /index.html, which will then hit the second location and do  
an external redirect again.

So either add a third “location = /index.html” to handle that, or avoid  
the internal rewrite by doing something like

try\_files /index.html =404

in the “location = /” block.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![daveyfx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b487fb/32.png) [@daveyfx](https://www.ruby-forum.com/u/daveyfx)\
**Post date:** [January 11, 2013, 12:26am UTC](https://www.ruby-forum.com/t/remove-uri-string/229354/8 "2013-01-11T00:26:08Z")

</div>

## Francis D. Wrote:

> As mentioned:
> 
> > }  
> > the internal rewrite by doing something like
> 
> try\_files /index.html =404
> 
> in the “location = /” block.
> 
> f

To all -

Thank you for your help with this. Francis put the puzzle together and  
the  
following is working out great for me.

server {  
server\_name  
[host1.domain.com](http://host1.domain.com)  
[host2.domain.com](http://host2.domain.com)  
…  
… (so on and so forth)

```
root /path/to/document/root;

location = / {
    try_files /index.html = 404;
}

location / {
    return 302 /;
}

```

}

> –  
> Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,234822,234914#msg-234914](http://forum.nginx.org/read.php?2,234822,234914#msg-234914)
