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 upgraded my nginx server from 0.7.x to 1.0.2 and I copied the old configuration file for the new nginx server. Everything worked fine, except for the if-directive. I had the following block of code in the old config file which doesn't seem to be working with the latest nginx version.

location /myapp {
         if (!-e $request_filename) {
                rewrite  ^/myapp/(.*)$  /myapp/index.php?q=$1  last;
          root /var/www;
          index index.php index.html index.htm;

Any idea what's wrong?

P.S.: Yes I know IfIsEvil and I did try exploring try_files, but I couldn't figure out how to pass only the part of the URI AFTER myapp/ as against passing the enter URI to index.php like so: try_files $uri index.php?q=$uri

share|improve this question

migrated from May 15 '11 at 7:28

This question came from our site for professional and enthusiast programmers.

up vote 1 down vote accepted

You want to redirect all requests to a common front controller.

location / {
    index index.php;
    try_files $uri $uri/ @handler; ## If missing pass the URI to front handler

location @handler {
    rewrite / /index.php;
    # Rewrite for @ErJab:
    # rewrite ^/myapp/(.*)$  /myapp/index\.php?q=$1  last;

location ~ .php$ { ## Execute PHP scripts 
share|improve this answer
You'd probably want to escape dot in regexp – Alexander Azarov May 16 '11 at 12:43
@Alaz, tnx fixed it. – i.amniels May 16 '11 at 13:10
Not in rewrite, in the location's regexp: location ~ \.php$ – Alexander Azarov May 16 '11 at 16:17
I have tested this config many times and it works :-) – i.amniels May 18 '11 at 9:19

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.