0

I've been trying to get this to work for a couple of hours now, but nothing really seems to work. I've got a Drupal site up and running, and the default location looks like this :

# Default location
location / {
  try_files $uri @rewrite;
}

location @rewrite {
  rewrite_log on;
  rewrite ^/(.*)$ /index.php?q=$1;
}

This works fine, and the end result of this is that all paths not pointing directly to the root (such as 'example.com/subdir1' and 'example.com/subdir1/subdir2') gets rewritten to index.php?q=[path].

However, it happens that I have a few subdirectories on the site which are 'real' subdirectories that contains index.php files. What I would like is to test whether any given subdirectory indeed has an index.php, and then run that one. This is one of my attempts which I thought would work:

# Default location
location / {
  try_files $uri @subdir @rewrite;
}

location @subdir {
  rewrite_log on;
  rewrite ^/(.*)$ $1/index.php;
}

location @rewrite {
  rewrite_log on;
  rewrite ^/(.*)$ /index.php?q=$1;
}

However, it does not work. I've also tried:

# Default location
location / {
  try_files $uri $uri/index.php @rewrite;
}

location @rewrite {
  rewrite_log on;
  rewrite ^/(.*)$ /index.php?q=$1;
}

That did not work either. I can't figure out what I am doing wrong?

For the record : my configuration file is Drupal & nginx : a sound "general purpose" configuration?

1 Answer 1

1

You will need to tell nginx to look for index.php files by using index. http://wiki.nginx.org/HttpIndexModule

Add this to either the server, http or location block:

index index.php index.html

Then your config should almost stay the same, but have a $uri/ check as well:

# Default location
location / {
  try_files $uri $uri/ @rewrite;
}

location @rewrite {
  rewrite_log on;
  rewrite ^/(.*)$ /index.php?q=$1;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .