Skip to content

Instantly share code, notes, and snippets.

@dtateii
Created October 10, 2014 19:44
Show Gist options
  • Save dtateii/278d4dddb3e6ec4ff0cc to your computer and use it in GitHub Desktop.
Save dtateii/278d4dddb3e6ec4ff0cc to your computer and use it in GitHub Desktop.
Apache Rewrites for static html site
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# Remove index.html if entered
RewriteCond %{REQUEST_URI} ^/index.html$
RewriteRule (.*) / [R=301,L]
# Remove display of .html for any html file request
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /.+\.html\ HTTP
RewriteRule ^(.+)\.html$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^.+$ %{REQUEST_FILENAME}.html [L]
</IfModule>
@dtateii
Copy link
Author

dtateii commented Oct 10, 2014

Given a typical Apache configuration, with mod_rewrite installed, this code could be added to a file named .htaccess at the web root to produce clean URLs on a static html site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment