Redirect help please this one's driving me mad!

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…

    RewriteRule ^$ home [L]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?([^\.]*)\..*$ [NC]
    RewriteCond %{REQUEST_URI} !^/?$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php?q=/_%1/pages/$1 [L,QSA]

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!

Any suggestions gratefully received - I can’t get my head around the
params from the condition and those from the rule and how to do this in
nginx!

Steve


Steve H. BSc(Hons) MIITP
http://www.greengecko.co.nz
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa

Hi Steve,

that’s a lot of apache nonsense :wink: that you shouldn’t need

check out:
http://nginx.org/en/docs/http/converting_rewrite_rules.html

another useful link with great commenting:
https://blog.engineyard.com/2011/useful-rewrites-for-nginx/

-Payam

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

Anyone??

Cheers,

steve

On Thu, 2014-03-20 at 22:14 -0700, Payam C. wrote:

-Payam

     RewriteCond %{REQUEST_FILENAME} !-d

Steve


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


Steve H. BSc(Hons) MIITP
http://www.greengecko.co.nz
Linkedin: http://www.linkedin.com/in/steveholdoway
Skype: sholdowa

On Sat, Mar 22, 2014 at 11:37:38AM +1300, Steve H. 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 H. 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
/dir/home.

     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 http://example.com/dir/fake

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

Good luck with it,

f

Francis D. [email protected]

On 22 Mar 2014, at 00.16, Francis D. [email protected] wrote:

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

Hi there,

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

I seem to be having problems sending to this mailing list… but I will
try again. Following is my response from a few days ago.
(The ^$ I remember as a weird one. REQUEST_URI is “/” if in httpd.conf.
But if you are within .htaccess it trims the directory path, so at the
webroot the REQUEST_URI is empty string, “”.)

======

Assuming I understand what those rules are trying to do, maybe something
along these lines? (needs testing)

location = / {
rewrite ^ /home;
}

location / {
if ($http_host ~* ^(?:www.)?([^.])…$) {
try_files $uri $uri/ /index.php?q=/_$1%$request_uri;
}
}

Then a regular .php$ handler which returns 404 if the script doesn’t
exist and passes to fastcgi if it does.

Jason

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs