request_uri changes after rewrite

Drew Wareham lists at ruby-forum.com
Wed Sep 17 03:55:06 MSD 2008


Hi,

In summary - after a rewrite where we strip some of the URI, $uri and
$request_uri both get updated to reflect the newly-redirected-to URI.
The wording of the manual leads me to believe that $request_uri is
supposed to contain the initially requested URI and it should not change
over subsequent redirects (unless they're 301/2)'s, which we're not
doing.

More info and a hopefully better explination - We're doing some pretty
hacky rewrites to get a website which was originally written to use
subdomains (each of which contains a seperately branded sub-site) to now
use uri arguments.

For example, what used to be:
http://test.example.com/news/articles/index.php
is now
http://www.example.com/test/news/articles/index.php

Unfortunately the site's codebase is huge, so we are unable to
realistically rewrite it to just use the new URI scheme, which is where
the rewrites come in.  The PHP backend of the site uses the
$_SERVER['SERVER_NAME'] variable to determine which subdomain is being
accessed, and then it loads the files necessary accordingly.

So far, we have got the site thinking it's being loaded from a subdomain
by using the fastcgi_param config directive and setting the SERVER_NAME
variable through it, and this works great.  The issue we're facing now
though is that we have to rewrite the URI to strip what used to be the
subdomain from it so the existing code loads the correct page.  For
example, instead of "www.example.com/test/news/..." we have to make it
"www.example.com/news/...", and we set "test" via fastcgi_param.  This
also is working correctly.

The problem we're facing is that everything except the initial PHP
script is not loading correctly, because after the rewrite, $uri no
longer has any reference to the subdomain variable.  According to the
manual, $request_uri is equal to the INITIAL URI, so I would think we
could use this to get the pre-redirect uri, but that also is getting
reset after the redirect.

Is there any way to get the initial URI after a redirect, so we can
continue to do our regex?

Thanks!  I hope that made sense.  I can post a config sample of what we
have currently if it would help.
-- 
Posted via http://www.ruby-forum.com/.





More information about the nginx mailing list