Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php [L]
Pretty much does what you want, but there is a fly in the ointment waiting to catch you out - and it's probably what is happening to you.
If you turn on rewrite logging and debugging in your http.conf file (or virtual host declaration), you should be able to see the issue. You do this by adding the following lines to your virtual host declaration:
Code:
RewriteLogLevel 9
RewriteLog /var/log/rewrite.log
When you do this you'll probably see your /contact correctly redirects to contact.php with an [INTERNAL_REDIRECT]. BUT......
Apache2 will, by default, then try and add a trailing slash and run the process again looking for index files. Now as you also have /contact/index.php it will find it and show it. To overcome this, we modify a few options and a complete working example is given below (naturally, you'll need to modify this).
Code:
<VirtualHost *:80>
DocumentRoot /home/user/www/public_html
ServerName mydomain.whatever
ServerAlias www.mydomain.whatever
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/user/www/public_html/>
ExpiresActive On
ExpiresDefault "now"
DirectoryIndex index.html index.php
Options -Indexes FollowSymLinks -MultiViews
AllowOverride All
DirectorySlash Off
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
RewriteLogLevel 9
RewriteLog /var/log/apache2/rewrite.log
</VirtualHost>
I suggest once you are done debugging, set RewriteLogLevel to 3.
This works on my test box so that if I call
http://domain.local/contact I get contact.php. If I call
http://domain.local/contact/ (note the trailing slash) I get /contact/index.php served.
Hope that helps in some small way
EDIT
I've just noticed you are using WAMP not LAMP, so it goes without saying you'll need to modify the paths of the log, error & rewrite files.
You may also be able to do this:
Code:
RewriteEngine on
DirectorySlash Off
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* $0.php [L]