-2

I am quite new to Nginx, so my apologies in advanced for any messups.

I am trying to rewrite my script titled 'test.php' to 'test.png', so when you go to 'test.png', it displays the php content, just simply a rewrote (spoofed) file extension.

This is what I currently have, however this just makes both 'test.php' and 'test.png' 404.

location ~ ^/test.php {

rewrite test.php test.png break;

}

0
0

Yeah, you got it the opposite direction.

Not saying it would work if you repaired that, but that depends on the rest of your configuration.

Also you need to know that regular expressions are used only if there is no other exact-match rule that would be preferred in that case.

Try this:

location /test.php {
    rewrite ^/test\.png$ /test.php last;
}

or this:

location ~ ^/test\.php$ {
    rewrite ^/test\.png$ /test.php last;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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