Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 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 So this is how I'm doing it:

    location ~* ^/users*$ {
            rewrite ^ permanent;

    location ~* \.php$ {
            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

How can I get this to work as intended?

share|improve this question

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

share|improve this answer
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 '11 at 14:46

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.