1

I have an issue with an Nginx location directive. I need to be able to send any URI through fastcgi so that it ends up in a PHP framework. But I also want to set up a rule whereby any URI beginning with /users gets redirected (let's say to http://www.google.com). So this is how I'm doing it:

    location ~* ^/users*$ {
            rewrite ^ http://www.google.com? permanent;
    }

    location ~* \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_intercept_errors on; # to support 404s for PHP files not found
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
    }

I can go to any URL and it will send it through the PHP framework I am using, so that part works. However, the /users* redirect does not work. If I comment out the second location direction (for the PHP files), the /users* redirect works, but it actually downloads the index.php as a file before redirecting to http://www.google.com.

How can I get this to work as intended?

1 Answer 1

1

The regex ^/users*$ probably doesn't match what you expect it to match. Something like ^/users.*$ or ^/users will be much more inclusive.

1
  • As I said, it works if you comment out the second location directive, so there's nothing wrong with the syntax. It's more just an issue with ordering/priority of directives in general.
    – John
    Oct 2, 2011 at 14:46

You must log in to answer this question.

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