Skip to content

Instantly share code, notes, and snippets.

@lukehedger
Created June 5, 2014 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukehedger/69c4609f049d6185c50c to your computer and use it in GitHub Desktop.
Save lukehedger/69c4609f049d6185c50c to your computer and use it in GitHub Desktop.
Remove URL file extensions using .htaccess
# ----------------------------------------------
# Quick method:
# ----------------------------------------------
Options +MultiViews
# With Apache MultiViews, the server will look for files that match the requested resource (eg. a request for "site.com/page" will serve "site.com/page.php")
# ----------------------------------------------
# Long method:
# ----------------------------------------------
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)$ $1.html [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]
# You'll need a RewriteCond/Rule set per file type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment