Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Possible Duplicate:
Need custom Nginx regex

Desired outcome is this:

http://www.example.com/about/?r=something

to this:

http://www.example.com/about.php/?r=something

This is what I got but it isn't working:

if (!-e $request_filename)
{
    rewrite ^/([^?]*[^?/])/?(\?.*)?$  /$1.php/$2  last;
    break;
}

What am I doing wrong here?

share|improve this question

marked as duplicate by voretaq7 Jul 24 '12 at 15:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You're wrong in assuming that the rewrite string matches GET arguments. –  VBart Jul 23 '12 at 21:40

1 Answer 1

You don't need a regex for this at all. Just add it to your existing try_files:

Example:

try_files $uri.php $uri $uri/ @404;

If you aren't (yet) using try_files, then convert soon, and in the meantime use something like this:

if (-e $request_filename.php) {
    rewrite ^(.+)$ $1.php last;
}

(I ripped this second example out of my notes from when I originally converted from Apache to nginx and wanted to have a URL /example load /example.php as Apache would do.)

share|improve this answer
    
I already use try_files, just can't get it working with try_files. Your example just gives me a error 500 page. I have rephrased my question here: serverfault.com/questions/410522/need-custom-nginx-regex –  RoboTamer Jul 24 '12 at 5:35
    
Sorry, I realized after I slept on it that try_files wouldn't work. The second block should have been fine, though. In any case, it's bad form to post duplicate questions; if you need to clarify your question you can just edit the original question. –  Michael Hampton Jul 24 '12 at 15:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.