Welcome! Log In Create A New Profile

Advanced

Trailing slash rewrite help

Kurt Hansen
July 18, 2009 01:28AM
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.

Thanks,

Kurt Hansen
Subject Author Posted

Trailing slash rewrite help

Kurt Hansen July 18, 2009 01:28AM

Re: Trailing slash rewrite help

Igor Sysoev July 18, 2009 03:24AM

Re: Trailing slash rewrite help

Kurt Hansen July 20, 2009 11:14AM

Re: Trailing slash rewrite help

Igor Sysoev July 21, 2009 05:22AM

Re: Trailing slash rewrite help

Kurt Hansen July 21, 2009 10:07AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 136
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready