0

Im trying to remove the .html from the url so that www.example.com/page.html would be www.example.com/page. I tried using .htaccess with this code :

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

My html code is simply : <a href = "page">link</a>

This didn't work as every time I click on the link, an error page shows up

Ggg Bbb
  • 17
  • 1

3 Answers3

1

I think you want to add and not remove .html (rewrite page to page.html)
You can use:

Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.html -f
RewriteRule ^(.+)/?$ $1.html [L]
Croises
  • 18,570
  • 4
  • 30
  • 47
0

Something like this should work.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 
Josh Stevens
  • 3,943
  • 1
  • 15
  • 22
0

I found the answer on - How to remove .html from URL. This was the only .htaccess script that worked:

RewriteEngine on
RewriteBase /
RewriteCond %{http://www.proofers.co.uk/new} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.proofers.co.uk/new/$1 [R=301,L]
Community
  • 1
  • 1
Ggg Bbb
  • 17
  • 1