RewriteEngine on # Rewrite /foo/bar to /foo/bar.phpRewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L] # Return 404 if original request is /foo/bar.phpRewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" RewriteRule .* - [L,R=404] # NOTE! FOR APACHE ON WINDOWS: Add [NC] to RewriteCond like this:# RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$" [NC]