Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to rewrite a specific path using nginx. I have setup my server using nginx/php-fpm/php and it is working fine.

I have the following server configuration:

server {
    listen 80;

    root /srv/www/;

    location ~ ^/index.php($|/) {
        fastcgi_split_path_info ^(.+.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include        fastcgi_params;

    location / {
       index index.php;
            try_files $uri /index.php?$args;

And this works. I.e. when I go to it renders the php file just fine. However I am now trying to rewrite a specific path /update/whatever to /update.php?var=whatever. In order to do this I have added the following location block to my config (before the location ~ ^/index.php($|/) { block):

location ~* ^\/update/(\w+)$ {
    rewrite ^/update/(\w+)$ /update.php?browser=$1 last;

But when I try to access the URL it downloads the php file instead of serving the parsed output from PHP.

I have also tried adding the fastcgi directives to that location block with the same result. Anybody can tell me what I have messed up in my config?

share|improve this question
up vote 1 down vote accepted

This line:

location ~ ^/index.php($|/) {

tells nginx to pass only index.php to php interpreter and you need it to also apply to other php files so more generic rule is required here:

location ~ ^/(.*).php($|/) {
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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