I created some pages .html
and put online. In the browser file extensions are visible. However I want to hide them to make urls more "friendly".
For example: instead of www.meusite.com/contato.html
I want only www.meusite.com/contato
to appear.
Searching (including similar questions here on the site) I saw that this can or should be done through the .htaccess
file. In many tutorials or answers the code below appears, but it did not work for me.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
ps: I would not like to turn my pages .html
into .php
because they are static pages.
UPDATE:
I placed the following code in the .htaccess file:
RewriteEngine On
RewriteRule ^([0-9A-Za-z-_]+)$ /$1.html
I ran the test with the "contact" page and it worked. In index.html
I changed the a
tag that links to the contact page as follows: From <a href="contato.html">Contato</a>
to <a href="contato">Contato</a>
. That is, inside the site, when linking one page with another, I took the file extensions. Apparently it worked. Is this recommended?