Skip to content

Instantly share code, notes, and snippets.

@juniovitorino
Created June 28, 2013 13:52
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 juniovitorino/5884821 to your computer and use it in GitHub Desktop.
Save juniovitorino/5884821 to your computer and use it in GitHub Desktop.
Remove file extension from urls's
# http://www.niallflynn.com/seo-news/remove-file-extension-from-urls/
<IfModule mod_rewrite.c>
AddType text/x-component .htc
RewriteEngine On
RewriteBase /
# remove .php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)/index$ $1/ [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment