Access index.html in folder without 301 redirect
The index
directive and the $uri/
element of the try_files
directive, has the side-effect of adding a trailing /
to directory names by performing an external redirect.
To avoid the external redirect and return an appropriate index file when presented with a slash-less directory name, implement the index
functionality explicitly within the try_files
directive:
location / { try_files $uri $uri/index.html $uri.php; expires 30d;}
Notice that .php
works only in the last element at this location. If you need to check for $uri/index.php
(in addition to $uri.php
) you can use a named location block - and move or copy your fastcgi configuration into it.
For example (based on your server block):
root /var/www/vhosts/site.com/htdocs;error_page 404 /404.php;location / { try_files $uri $uri/index.html @php; expires 30d;}location @php { try_files $uri.php $uri/index.php =404; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ... fastcgi_pass ...;}location = /index.php { return 301 $scheme://$host; }location = /index { return 301 $scheme://$host; }location /. { return 404; }location ~* \.php(/|$) { rewrite ^(.*)\.php $1 last; }include "ssl_offloading.inc";