# Redirecting any URI to a unique one

**URL:** <https://www.ruby-forum.com/t/redirecting-any-uri-to-a-unique-one/135711>\
**Category:** NGINX\
**Created:** [April 24, 2008, 11:56am UTC](https://www.ruby-forum.com/t/redirecting-any-uri-to-a-unique-one/135711 "2008-04-24T11:56:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [April 24, 2008, 11:56am UTC](https://www.ruby-forum.com/t/redirecting-any-uri-to-a-unique-one/135711/1 "2008-04-24T11:56:16Z")

</div>

Hi,

I have a website, let’s call it [www.mysite.com](http://www.mysite.com)

On this website, I have a servlet running on tomcat at:  
[http://127.0.0.1:8080/servlet/service1](http://127.0.0.1:8080/servlet/service1)

From the outside world I want people to access that servlet using the  
following URL:  
[http://servlet.mysite.com](http://servlet.mysite.com)

Currently in my nginx conf file I have:

server {  
server\_name [servlet.mysite.com](http://servlet.mysite.com);

location / {  
proxy\_pass [http://127.0.0.1:8080/servlet/service1](http://127.0.0.1:8080/servlet/service1);  
}  
}

The problem is that if anyone enters a URL such as  
[http://servlet.mysite.com/somestuff](http://servlet.mysite.com/somestuff), Tomcat spits back an ugly 404  
page. So I would like that whatever request comes in, tomcat only sees  
[http://servlet.mysite.com](http://servlet.mysite.com), and thus serves the only servlet I have  
available.

Should I use a rewrite for that? Am I doing it the correct way? I have  
tried a few things but they all failed, the page couldn’t load  
anymore.

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [April 24, 2008, 2:51pm UTC](https://www.ruby-forum.com/t/redirecting-any-uri-to-a-unique-one/135711/2 "2008-04-24T14:51:19Z")

</div>

I am advancing a bit.

If I enter [http://servlet.mysite.com](http://servlet.mysite.com), I get the servlet.

If I enter [http://servlet.mysite.com/whatever](http://servlet.mysite.com/whatever), for some magical  
reason, I get redirected with: [http://servlet.mysite.com/index.jsp](http://servlet.mysite.com/index.jsp) and  
Firefox display that it failed to load the page.

I don’t know who is appending this index.jsp, it is certainly not me.

* * *

server {  
listen 80;  
server\_name [servlet.mysite.com](http://servlet.mysite.com);

error\_log /usr/local/nginx/logs/servlet.log notice;

location / {

```
rewrite /.+ / break;

root /usr/local/tomcat-4.1/webapps/servlet/WEB-INF/classes;
index index.html;

proxy_redirect off;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;

proxy_pass http://127.0.0.1:8080/servlet/service1;

```

} # End of the location /  
} # End of server

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [April 24, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/redirecting-any-uri-to-a-unique-one/135711/3 "2008-04-24T18:17:36Z")

</div>

Okay I got it working, I had to append the “last” flag instead of  
“break”. But I don’t understand the difference between the two, the  
wiki is not crystal clear about that. Does anyone have a good  
explanation or can redirect me to an equivalent apache one?

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [April 24, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/redirecting-any-uri-to-a-unique-one/135711/4 "2008-04-24T14:54:51Z")

</div>

Actually this is the full error message:

Too many redirects occurred trying to open  
“[http://sogenactif.railsbuntu.ath.cx/index.jsp](http://sogenactif.railsbuntu.ath.cx/index.jsp)”. This might occur if  
you open a page that is redirected to open another page which then is  
redirected to open the original page.
