Created
October 10, 2014 19:44
-
-
Save dtateii/278d4dddb3e6ec4ff0cc to your computer and use it in GitHub Desktop.
Apache Rewrites for static html site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.