I have the following rewrite rule I'm trying:

            location / {
                    index index.php index.html;
                    rewrite  ^/test$  /test.php  break;

And I also have:

            location ~ \.php$ {
                    include         fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME /home/sites/default$fastcgi_script_name;
                    fastcgi_index   index.php;

Normal php files work ok, but it seems my redirect is just downloading the php file I'm redirecting to, rather than parsing it.

What am I missing? I got the file to load, instead of download by putting the fastcgi stuff in the first location block, but it still didn't parse as php.


Change break to last.

Because the new URL will need to be processed by a different location, you need to have nginx restart processing for the new rewritten URL, which is only done when you use last in the rewrite rule.

See the docs for a fuller explanation.

  • @TamasKalman Eh? You don't look like the OP. If you are having a problem, you can ask a new question. – Michael Hampton May 28 at 1:51

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.