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 the below .htaccess file in apache that redirects all request to app/index.php with or without a GET parameter. I just installed NGINX and my application won't run. Can anyone assist in replicating same functionality in NGINX? Thanks.

RewriteEngine on    

Options -Indexes

RewriteRule    ^$ app/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule ^(.+)$ app/index.php?url=$1 [QSA,L]
share|improve this question

migrated from Jul 16 '12 at 7:27

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

Use the rewrite module. Something like this should do it:

location / {
  autoindex off;

  rewrite ^/$ app/ last;
  if (!-e $request_filename) {
    rewrite ^/(.*)$ app/index.php?url=$1;
share|improve this answer

Use try files

There is no need to use the rewrite module for most of that config.

The apache rewrite rules mean:

  • RewriteRule ^$ app/ [L] - send the url / to the app dir
  • RewriteCond %{REQUEST_FILENAME} !-d - if the request is not a dir
  • RewriteCond %{REQUEST_FILENAME} !-f - if the request is not a file
  • RewriteCond %{REQUEST_FILENAME} !-l - if the request is not a symlink
  • Then send the request to app/index.php?url=$1

In nginx the equivalent is:

# No automatic directory listings
autoindex off;

# Send the root url to the app dir
index index.php;
rewrite ^/$ app/ last;

# check if the url matches a file, directory and if not send to app/index.php
try_files $uri $uri/ app/index.php?url=$uri;

The check for a symlink is superfluous since a symlink is also a file or directory.

share|improve this answer

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.