Last active
June 1, 2017 04:46
-
-
Save josephspurrier/9836107 to your computer and use it in GitHub Desktop.
Nginx root configuration for Trailing Slash Solution - http://josephspurrier.com/trailing-slash-solution/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http { | |
# Ensure index.php is only allowed as index | |
index index.php; | |
server { | |
listen 80; | |
server_name localhost; | |
root /var/www; | |
# Manage the slashes via rewrites | |
merge_slashes off; | |
# Strip main index.php and query string | |
if ( $request_uri ~* ^/+index\.php\?+) { | |
return 301 /; | |
} | |
# Strip multiple slashes and query string | |
rewrite "^/+(.*[^/])/{2,}(.*)" /$1/$2 permanent; | |
# Strip multiple leading slashes and query string | |
rewrite "^/{2,}(.*)" /$1? permanent; | |
# Add a trailing slash to folders like Apache | |
if (-d $request_filename) { | |
rewrite /(.*[^/])$ /$1/? permanent; | |
} | |
location @rewrites { | |
# Send all requests to index.php | |
rewrite ^ /index.php last; | |
} | |
location ~* \.php$ { | |
try_files $uri $uri/ @rewrites; | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini | |
# With php5-cgi alone: | |
fastcgi_pass 127.0.0.1:9000; | |
# With php5-fpm: | |
#fastcgi_pass unix:/var/run/php5-fpm.sock; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
} | |
location / { | |
try_files $uri $uri/ @rewrites; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sub folder Nginx config file is available here: https://gist.github.com/josephspurrier/9848964.
By using these two scripts, both applications will handle pages the same.