13

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$ {
                    fastcgi_pass    127.0.0.1:9000;
                    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.

0

1 Answer 1

27

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.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .