views:

303

answers:

1

I'm trying to set-up nginx rewrite rules as the following:

Original structure:

domain.com/index.php?site=project

Now I tried to mask it using the nginx rewrite engine:

if (-f $request_filename) {
        break;
      }
      if (!-f $request_filename) {
        rewrite ^/(.+)$ /index.php?site=$1 last;
        break;
      }

How do I forbid folders (stuff ending with a slash) and non-existent files? I read a lot about

try_files

but I can't get it to work.

at the moment I have

    try_files $uri $uri/ @app;

and

location @app {
rewrite ^/ /404.php last;
}

but it won't work. What am I doing wrong?

Also: Do I need to alter my PHP code? Or is pure rewrite fine?

A: 

You can turn off autoindex to prevent users from looking in folders. I do't know what you mean with 'forbid non-existent files'. The visitor just gets a 404.

Frank