redirect help please... this one's driving me mad!

Francis Daly francis at
Sat Mar 22 00:16:54 UTC 2014

On Sat, Mar 22, 2014 at 11:37:38AM +1300, Steve Holdoway wrote:

Hi there,

> Sadly not one mention of the correct way to handle %1 and $1 in either
> of these pages.

Can you describe in words what you want your nginx config to do?

As in: this request leads to that response.

I can try guessing at what your apache config probably does; but you're
probably best-placed to test it.

> > On 2014-03-20, 9:44 PM, Steve Holdoway wrote:
> > > I'm tryiing to migrate a site that uses codeigniter behind modx to draw
> > > pages, and this is the block that breaks the site when I remove it
> > > from .htaccess...

So, .htaccess appears in a directory, and the directory prefix is stripped
from the url before Rewrite considers it. (Maybe. What do your apache docs
say?. You're more likely to get correctly corrected answers to "what
does this apache config do" on an apache list than on a non-apache list.)

So, the request is something below /dir/.

> > >          RewriteRule ^$ home [L]

If the request is exactly /dir/, then rewrite (or perhaps redirect?) to

> > >          RewriteCond %{HTTP_HOST} ^(?:www\.)?([^\.]*)\..*$ [NC]

If there is at least one "." in the Host header, store the first
.-separated part (ignoring the leading "www.", if it is there) as (say)
$site ...

> > >          RewriteCond %{REQUEST_URI} !^/?$
> > >          RewriteCond %{REQUEST_FILENAME} !-f
> > >          RewriteCond %{REQUEST_FILENAME} !-d

and if the request is not exactly "/" (or is that "/dir/"?), and the
corresponding file-or-directory does not exist...

> > >          RewriteRule (.*) index.php?q=/_%1/pages/$1 [L,QSA]

then rewrite (or perhaps redirect) to /dir/index.php?q=/_$site/pages/$uri.

But $uri might be a version of $request_uri, and might be without the
leading /dir/ part.

See apache docs and/or your testing to know what is actually there, then
ask here or check nginx docs for a suitable equivalent nginx variable.

> > > Does anyone have an idea on how to rewrite that? From debugging code
> > > added to the site, it seems to go through index.php 3 times for each
> > > page draw!

  curl -i

Does that return a http redirect, or some specific content involving
the words "example" and "fake"?

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list