Remove .php extention and add a slash htaccess


I have a website where most files have a php extention, and want to remove the exention and add a slash using htaccess.

So for example instead of

I’d like…

I’ve tried loads of scripts from the web. They seem to work in that they remove the .php, but kept getting a 404. So I removed the .php extention from one of the files so it didn’t get a 404 but the file wasn’t then treated as a php file and showed the php code in the browser.

RewriteEngine on

RewriteCond %{THE_REQUEST} [1]{3,9}\ /(.*)\.php\ HTTP/ [NC]
RewriteRule .+ [R=301,QSA]

Can anyone tell me what I’m doing wrong?


  1. A-Z ↩︎



  1. You’re using mod_rewrite to do your job (coding links) as webmaster, that is, you’re going the wrong way! Use mod_rewrite to ADD the .php extension to extensionless URIs.

  2. By telling Apache that your links are subdirectories when they’re really extensionless filenames makes everything overly complicated (and results in a directory level offset which will make your relative links worthless).

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.