Last active
July 19, 2023 05:19
-
-
Save hohl/e6a5af65c216ee666adc to your computer and use it in GitHub Desktop.
rewrite URLs to remove .html ending and always hide "index.html"
This file contains 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 / | |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removes all ".html" suffixes from URLs and always applies "www" before hostnames without a leading "www" prefix.