Skip to content

Instantly share code, notes, and snippets.

@azhawkes
Created January 22, 2014 14:15
Show Gist options
  • Save azhawkes/8559395 to your computer and use it in GitHub Desktop.
Save azhawkes/8559395 to your computer and use it in GitHub Desktop.
Apache mod_rewrite config to treat requests for /something as /something.html behind the scenes. Using this for a static Jekyll site because I don't want the .html extensions visible to end users.
RewriteEngine on
# Automatically rewrite /something -> something.html
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.html -f
RewriteRule /(.*)$ /$1.html [L]
# Strip off .html extensions from the request and redirect
RewriteCond %{REQUEST_URI} ^(.+)\.html$
RewriteRule /(.*)\.html$ /$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment