Forum: NGINX Simple Rewrite Question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alan W. (Guest)
on 2009-01-16 13:03
(Received via mailing list)
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/

would be rewritten to:

 http://xyz/index.htm

and so on ...

 http://xyz/mytest/ -> http://xyz/mytest/index.htm

BUT 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
Alan W. (Guest)
on 2009-01-16 13:21
(Received via mailing list)
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?
Daniele M. (Guest)
on 2009-01-16 13:39
(Received via mailing list)
Alan W. ha scritto:
> so a request:
>  http://xyz/
> would be rewritten to:
>  http://xyz/index.htm
> and so on ...
>  http://xyz/mytest/ -> http://xyz/mytest/index.htm
> BUT http://xyz/mytest is to be untouched!  Only if it has a / at the end.

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

Daniele
Igor S. (Guest)
on 2009-01-16 14:32
(Received via mailing list)
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${uri}index.cfm$is_args$args;
         }
Alan W. (Guest)
on 2009-01-16 15:02
(Received via mailing list)
thank you that's great
This topic is locked and can not be replied to.