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

2
  • This Q&A should help. Remove HTML extension from URL Commented Mar 29, 2016 at 22:59
  • I found the right answer on that page. Thanks Commented Mar 30, 2016 at 0:01

3 Answers 3

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]
Sign up to request clarification or add additional context in comments.

Comments

0

Something like this should work.

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

Comments

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.