๐Ÿ“š node [[removing html extension from urls with apache]]
๐Ÿ“• text contributed by @neil ๐Ÿ”— ๏ธ๐Ÿ‘ ๏ธ๐Ÿ“

Removing .html extension from URLs with Apache


There's loads of snippets for doing this knocking around on the web. This one worked best for me:


I just put it in .htaccess.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

# Remove the .html extension
    RewriteCond %{THE_REQUEST} ^GET\ (.*)\.html\ HTTP
    RewriteRule (.*)\.html$ $1 [R=301]

# Remove index and reference the directory
    RewriteRule (.*)/index$ $1/ [R=301]

# Remove trailing slash if not a directory
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /$
    RewriteRule (.*)/ $1 [R=301]

# Forward request to html file, **but don't redirect (bot friendly)**
    RewriteCond %{REQUEST_FILENAME}.html -f
    RewriteCond %{REQUEST_URI} !/$
    RewriteRule (.*) $1\.html [L]
Receiving pushes... (requires JavaScript)
Loading context... (requires JavaScript)
๐Ÿ“– stoas (collaborative spaces) for [[removing html extension from urls with apache]]