Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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_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?

share|improve this question

1 Answer 1

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.