Skip to content

Instantly share code, notes, and snippets.

@josephspurrier josephspurrier/nginx.conf
Last active Jun 1, 2017

What would you like to do?
Nginx root configuration for Trailing Slash Solution -
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:
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
location / {
try_files $uri $uri/ @rewrites;

This comment has been minimized.

Copy link
Owner Author

josephspurrier commented Mar 29, 2014

A sub folder Nginx config file is available 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.