Ggg Bbb
Ggg Bbb

Reputation: 17

Remove .html from url with .htaccess

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

Upvotes: 0

Views: 158

Answers (3)

Ggg Bbb
Ggg Bbb

Reputation: 17

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]

Upvotes: 0

Croises
Croises

Reputation: 18671

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]

Upvotes: 1

Josh Stevens
Josh Stevens

Reputation: 4221

Something like this should work.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301] 

Upvotes: 0

Related Questions