Skip to content

Instantly share code, notes, and snippets.

@dvlden
Last active September 11, 2017 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dvlden/facc2cf9eadc931557c4 to your computer and use it in GitHub Desktop.
Save dvlden/facc2cf9eadc931557c4 to your computer and use it in GitHub Desktop.
Pretty URL's are always nice and great in many cases. This is how you rewrite your URL's to remove / strip off php extension
<IfModule mod_rewrite.c>
# remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L]
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment