Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Redirect Problems (with try_files)

$
0
0
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.

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>