Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nginx sub folder configuration for Trailing Slash Solution -
location @testrewrites {
# Send all requests to index.php
rewrite ^ /test/index.php last;
# Else use this location block
location ~* ^/test/.*\.php$ {
# Strip subdir index.php and query string
if ( $request_uri ~* ^/(.*)/index\.php\?+) {
rewrite (?i)^/(.*)/index\.php /$1/? permanent;
try_files $uri $uri/ @testrewrites;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
# Else use this location block
location ~* ^/test/.* {
try_files $uri $uri/ @testrewrites;

This comment has been minimized.

Copy link
Owner Author

josephspurrier commented Mar 29, 2014

If you place a dynamic application using the Front Controller pattern (index.php) in a sub folder, add this above the first location block and then change the 6 instances of 'test' to your folder name. This requires you to use the Nginx root folder configuration here:

By using these two scripts, both applications will handle pages the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.