Skip to content

Instantly share code, notes, and snippets.

@hohl
Last active July 19, 2023 05:19
Show Gist options
  • Save hohl/e6a5af65c216ee666adc to your computer and use it in GitHub Desktop.
Save hohl/e6a5af65c216ee666adc to your computer and use it in GitHub Desktop.
rewrite URLs to remove .html ending and always hide "index.html"
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
RewriteRule (.*)\.html$ $1 [R=301]
RewriteRule (.*)/index$ $1/ [R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.html [L]
</IfModule>
@hohl
Copy link
Author

hohl commented Mar 9, 2016

Removes all ".html" suffixes from URLs and always applies "www" before hostnames without a leading "www" prefix.

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