Best way to remove .php extension from urls with 301 redirect?

greyhat

English Gent
Nov 30, 2009
853
8
0
UK
Any .htaccess experts out there?

I am struggling to do this.

I can get it to work but just not also with a 301 redrect so I effectively end up with duplicate pages.

Any help appreciated!

Have some boobs : )
qDLrUkf.jpg
 


This should do the trick for you - (put in .htaccess of root folder):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Remember never to copy directly from browser (or this message) as syntax gets corrupted. Copy and paste into Notepad++ first, check characters, and then paste into .htaccess. This should be ok as it's usually (") and (,) that get corrupted.
 
You could put them in a directory and then you don't need to go to the .php file... just saying.