# Rewrite rule help

**URL:** <https://www.ruby-forum.com/t/rewrite-rule-help/205217>\
**Category:** NGINX\
**Created:** [April 1, 2011, 5:01am UTC](https://www.ruby-forum.com/t/rewrite-rule-help/205217 "2011-04-01T05:01:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 1, 2011, 5:01am UTC](https://www.ruby-forum.com/t/rewrite-rule-help/205217/1 "2011-04-01T05:01:42Z")

</div>

hi

i’m running nginx with tomcat. I tried to rewrite all the incoming url  
with /en appended. ex: [www.example.com/main/index.html](http://www.example.com/main/index.html) will get rewrite  
to [www.example.com/en/main/index.html](http://www.example.com/en/main/index.html)

Following is my nginx config:

upstream [www.example.com](http://www.example.com) {  
server localhost:8080;  
}

location ^~ / {  
index index.html index.htm;  
rewrite ^ [http://www.example.com/en$request\_uri](http://www.example.com/en$request_uri) break;  
}

location ^~ /en {  
index index.html index.htm;  
proxy\_pass [http://www.example.com/](http://www.example.com/);  
}

When i just do [www.example.com/main/index.html](http://www.example.com/main/index.html), it rewrites to the new  
url and page shows. But when i tried to write an url without .htm or  
.html extension, the browser complains about page not found and return  
404. such as “[www.example.com/main/new](http://www.example.com/main/new)” I got the 404 error on my  
Tomcat log. Before this rewrite rule, the page can be loaded without  
any problem.

here is my tomcat config:

dir \*.htm /en/\* 404 /errors/503.htm

any help is apprecaite.

Thank You

Steve Z.

---

<div class="post-metadata">

**Author:** ![stevezhuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@stevezhuo](https://www.ruby-forum.com/u/stevezhuo)\
**Post date:** [April 1, 2011, 8:22am UTC](https://www.ruby-forum.com/t/rewrite-rule-help/205217/2 "2011-04-01T08:22:46Z")

</div>

On Fri, Apr 01, 2011 at 05:01:42AM +0200, Steve Z. wrote:

> ```
> server localhost:8080;
> }
> 
> ```
> 
> dir \*.htm /en/\* 404 /errors/503.htm

location ^~ / {  
rewrite ^ [http://www.example.com/en$request\_uri](http://www.example.com/en$request_uri) permanent;  
}

location ^~ /en {  
proxy\_pass [http://www.example.com](http://www.example.com);  
}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![stevezhuo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/da6949/32.png) [@stevezhuo](https://www.ruby-forum.com/u/stevezhuo)\
**Post date:** [April 1, 2011, 10:10pm UTC](https://www.ruby-forum.com/t/rewrite-rule-help/205217/3 "2011-04-01T22:10:25Z")

</div>

Thank You Igor. it works fine now

Steve Z.
