Skip to content

Instantly share code, notes, and snippets.

@nonsalant
Last active March 28, 2022 16:10
Show Gist options
  • Save nonsalant/442b55ce1daa9c4a6e11 to your computer and use it in GitHub Desktop.
Save nonsalant/442b55ce1daa9c4a6e11 to your computer and use it in GitHub Desktop.
Remove .php extension from URL's and add a trailing slash
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment