# Simple Rewrite Question

**URL:** <https://www.ruby-forum.com/t/simple-rewrite-question/157892>\
**Category:** NGINX\
**Created:** [January 16, 2009, 12:03pm UTC](https://www.ruby-forum.com/t/simple-rewrite-question/157892 "2009-01-16T12:03:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alanwatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@alanwatts](https://www.ruby-forum.com/u/alanwatts)\
**Post date:** [January 16, 2009, 12:03pm UTC](https://www.ruby-forum.com/t/simple-rewrite-question/157892/1 "2009-01-16T12:03:01Z")

</div>

Morning all.

I have a very simple request to clean up

I basically need to catch URI’s that end with “/” and if they do, append  
index.htm to them. The upstream proxy doesn’t like to see “/”.

so a request:

[http://xyz/](http://xyz/)

would be rewritten to:

[http://xyz/index.htm](http://xyz/index.htm)

and so on …

[http://xyz/mytest/](http://xyz/mytest/) → [http://xyz/mytest/index.htm](http://xyz/mytest/index.htm)

BUT [http://xyz/mytest](http://xyz/mytest) is to be untouched! Only if it has a / at the  
end.  
I want to proxy\_pass these to the backend. I am struggling to get this  
right, so any pointers/help would be appreciated

thanks

---

<div class="post-metadata">

**Author:** ![alanwatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@alanwatts](https://www.ruby-forum.com/u/alanwatts)\
**Post date:** [January 16, 2009, 12:21pm UTC](https://www.ruby-forum.com/t/simple-rewrite-question/157892/2 "2009-01-16T12:21:20Z")

</div>

I think i blundered upon the solution myself:

```
    location ~* /$ {
            rewrite (.*) $1index.cfm;
            proxy_pass http://beta.yourli.st;
    }

    location / {
            proxy_pass http://beta.yourli.st;
    }

```

This does indeed do the trick; what i was missing the “~\* /$” in the  
location directive.

Is there a more efficient way of doing this?

---

<div class="post-metadata">

**Author:** ![alanwatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@alanwatts](https://www.ruby-forum.com/u/alanwatts)\
**Post date:** [January 16, 2009, 12:39pm UTC](https://www.ruby-forum.com/t/simple-rewrite-question/157892/3 "2009-01-16T12:39:35Z")

</div>

Alan W. ha scritto:

> so a request:  
> [http://xyz/](http://xyz/)  
> would be rewritten to:  
> [http://xyz/index.htm](http://xyz/index.htm)  
> and so on …  
> [http://xyz/mytest/](http://xyz/mytest/) → [http://xyz/mytest/index.htm](http://xyz/mytest/index.htm)  
> BUT [http://xyz/mytest](http://xyz/mytest) is to be untouched! Only if it has a / at the end.

try this:  
rewrite ^/(.\*)/$ /$1/index.htm;

Daniele

---

<div class="post-metadata">

**Author:** ![alanwatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@alanwatts](https://www.ruby-forum.com/u/alanwatts)\
**Post date:** [January 16, 2009, 1:32pm UTC](https://www.ruby-forum.com/t/simple-rewrite-question/157892/4 "2009-01-16T13:32:11Z")

</div>

On Fri, Jan 16, 2009 at 11:11:29AM +0000, Alan W. wrote:

> This does indeed do the trick; what i was missing the “~\* /$” in the  
> location directive.
> 
> Is there a more efficient way of doing this?

You may also try

```
     location / {
         proxy_pass http://beta.yourli.st;
     }

     location ~* /$ {
         proxy_pass 

```

[http://beta.yourli.st$](http://beta.yourli.st$){uri}index.cfm$is\_args$args;  
}

---

<div class="post-metadata">

**Author:** ![alanwatts](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@alanwatts](https://www.ruby-forum.com/u/alanwatts)\
**Post date:** [January 16, 2009, 2:02pm UTC](https://www.ruby-forum.com/t/simple-rewrite-question/157892/5 "2009-01-16T14:02:12Z")

</div>

thank you that’s great
