James James - 1 month ago 6
Apache Configuration Question

Removing the .php extension with mod_rewrite

I want a mod_rewrite rule set so I can refer to a page without the .php extension, but have that rewritten to include the php extension. This will be running on a 1&1 server.

Are there any good references so I can learn more myself?

Answer
RewriteEngine On
RewriteRule something something.php [L]

http://example.com/something will be handled as if it was a request for something.php

To redirect all requests that are not a physical file to the same name but with .php:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
Comments