0

I'm trying to hide extensions from my website. I use both .php and .html i have a .htaccess file that hides only html, I don't know how to make it hide .php as well .

RewriteEngine on

RewriteBase /

#Removes .html extension
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.html\sHTTP/.+
RewriteRule ^(.+)\.html $1 [R=301,L]

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

I tried to copy and paste the code next to the one that i have and replace .html with .php but it didn't work it gave me an error with page not found.

What should I write to hide both .php and .html ?

EDIT: I know there are many questions about that, but i couldn't get it to work with the information that i've got from those.

Eduard Valentin
  • 179
  • 3
  • 20
  • That's the wrong approach in both ways. Redirecting old URLs to extensionless ones is a workaround. Fixing existing links in HTML should be the first step. And the second rewrite block should rather check for `-f` existence of `%{REQUEST_FILENAME}.php` and only then rewrite. (Can't have two opposing rules.) – mario Sep 30 '15 at 14:57
  • What about just adding `RewriteRule ^([^\.]+)$ $1.php [NC,L]`? – Krii Sep 30 '15 at 14:58
  • @mario Do you mean , I should my html links to extensionless ones ? – Eduard Valentin Sep 30 '15 at 15:01
  • @Krii I added it but nothing changes. – Eduard Valentin Sep 30 '15 at 15:01
  • I have seen this work before `^([^.]+?)/?$ $1.php [L]` – Krii Sep 30 '15 at 15:09

0 Answers0