Trailing slash rewrite help

Igor Sysoev is at rambler-co.ru
Sat Jul 18 11:24:47 MSD 2009


On Sat, Jul 18, 2009 at 01:28:12AM -0400, Kurt Hansen wrote:

> Hello,
> 
> I'm using nginx as a reverse proxy to a mod_perl backend server and am 
> having trouble with my rewrite rule in the case of a missing trailing 
> slash on a subdirectory.
> 
> For example, I want
> 
> www.example.com/action mapped to the example/action/ directory on the 
> mod_perl server.
> 
> However, what happens is that www.example.com/action is mapped to 
> example/example/action/
> 
> Here are  the relevant location directives where the rewrite is done:
> 
>     location /example/ {
>        # root   html;
>        index  index.htm;
> 
>        rewrite  ^/example(.*)/$ /example/$1/index.htm break;
> 
>        proxy_redirect off;
>        proxy_pass http://cweb;
>  }
> 
> 
>     location / {
>        # root   html;
>        index  index.htm;
> 
>        rewrite  ^/$ /example/index.htm break;
> 
>        rewrite  ^/(.*) /example/$1 break;
> 
>        proxy_pass http://cweb;
>    }
> 
> I think what is happening is that the rewrite comes out as 
> /example/action then nginx adds the trailing slash and it gets run 
> through the re-write again. I added the /example/ location directive so 
> at least the right pages are displayed, but the URL comes back to the 
> browser as www.example.com/example/action/
> 
> The nginx server is also an NFS server so the files reside on the nginx 
> server. I've tried an if (-d $request_filename) but that doesn't work.
> 
> Any help would be greatly appreciated.

Probably, you need just:

location / {
    proxy_pass http://cweb/example/;
}

Also, you need to set "Index index.htm" on mod_perl side.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list