Useful Nginx Hacks

The Regular Expression translates to: “rewrite all URLs without any ‘.’ (dot) in them that don’t end with a ‘/’ to the URI + ‘/'” Or simply: “If the URI doesn’t have a period and does not end with a slash, add a slash to the end”.

rewrite ^([^.]*[^/])$ $1/ permanent;

The reason for only rewriting URI’s without dots in them makes it so any file with a file extension doesn’t get rewritten. For example your images, css, javascript, etc and prevent possible redirect loops if using some php framework that does its own rewrites also

This very simply rewrites all URI’s that don’t have periods in them to your index.php (or whatever file you would execute your controller from).

rewrite ^([^.]*)$ /index.php;

Share your thoughts by leaving a comment below.