Skip to content

Instantly share code, notes, and snippets.

@mabutler
Created August 12, 2016 20:08
Show Gist options
  • Save mabutler/17d1e6c720abda7b2de27c1ec534f395 to your computer and use it in GitHub Desktop.
Save mabutler/17d1e6c720abda7b2de27c1ec534f395 to your computer and use it in GitHub Desktop.
RewriteEngine On
RewriteBase /
# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.+)/$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^(.*)/$ $1.php [L]
# Force trailing slash
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .*[^/]$ $0/ [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment