Reputation: 23
So I've searched very hard on trying to understand the differences between these two pieces of code, but I could not find it. I am trying to remove the ".html" extension from the url but I always see two different codes being used from different websites.
The first code is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ http://example.com/$1 [R=301,L]
The second code is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html
From my understanding the first code seems to replace any characters that used to be in that .html path (eg. example.com/home.html) to replace it without the .html extension (eg. example.com/home). Both seems to keep coming up however, in many different websites. That is why I would like to ask if anyone know the differences between the both and what both of these pieces of codes actually mean?
Any help would be appreciated.
Upvotes: 0
Views: 43
Reputation: 944003
The first matches any request for a path ending in .html
and tells the browser that it should ask for the same path, on example.com
without the .html
.
The second matches any request for any path and tells the server to add .html
to the end of it and deliver that to the browser.
Upvotes: 2