How will you hide all file extentions like .php to counter Search engine optimization

/page => /page.php

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$           %{REQUEST_FILENAME}.php [L]

This does not work...

edit

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.php$ [NC]
RewriteRule ^(.*)([^/]*)$       /$1$2.php [QSA,L]

You've written some strange problems inside your code!

  • %{REQUEST_FILENAME} already consists of the file-extension, which means you are requesting personal files wich finishes with .php.php, along with the -f-flag, you're checking if this type of file is available. Also, there really is you don't need to see if the asked for file is available for which for you to do.
  • Your RewriteRule would rewrite any us dot-php-file towards the same URL along with an additional .php. So index.php would become index.php.php
  • What for may be the exclamation mark in the beginning of the RewriteRule?

Fixing these errors, you receive something similar to:

RewriteRule (.*)\.php$ $1/

You should use $1, $2, $... within the right a part of your expresison to gain access to the n-th match between brackets () around the left.

To learn more about mod_rewrite, see here. Maybe it will help to appear there every so often. )