Welcome! Log In Create A New Profile

Advanced

Redirect Problems (with try_files)

Posted by rsmck 
Redirect Problems (with try_files)
October 25, 2013 12:37PM
Try as I may I can't get this to work...

I am trying to migrate from apache which was configured to accept a URL with or without extensions (multiViews I think) e.g.

/directory/page was equivalent to /directory/page.php

I am trying to do this in Nginx but also have a number other rewrite rules (to migrate old URLs to new ones) so have a configuration like this;

location / {
try_files $uri $uri/ @oldurls @api @noexten;
error_page 404 /404.html;
}

location @noexten {
rewrite ^(.*)$ $1.php last;
}

location @api {
rewrite ^/api /api.php break;
}

location @oldurls {
rewrite ^/old/path$ /new/page redirect;
......
}

WITHOUT the @noexten it works fine (but obviously files don't worth without the extension) ... but the @oldurls work as expected

As soon as I add the @noexten rule in the log only shows matches for this one (and obviously everything matches it) which makes my files without extensions work as expected, but breaks every other rewrite rule... I thought try_files would only try the next one if it didn't exist in a previous one ?

Lastly I also tried
try_files $uri $uri/ $uri.php $uri/index.php;

Which unfortunately serves up the raw PHP code rather than passing it through the php rule.

Any advice anyone can offer would be much appreciated.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 210
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready