when i am putting this code into .htaccess file for hide the .php extension am getting some error like Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
#Remove PHP extension from links
RewriteEngine On
RewriteCond %{REQUEST_URI}!(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule (.*)/$1.php[L]
RewriteCond %{THE_REQUEST}^[A-Z]{3,9}\/([^.]+\.)+php\HTTP
RewriteRule ^(.+)\.php$/$1[R=301,L]
It looks like you copied this code from somewhere, but the spaces didn't copy with it. Therefore the flags and the first and second argument of RewriteCond
's and RewriteRule
's were stitched together. This is, of course, invalid syntax and produces a 500 Internal Server Error. You can find documentation for mod_rewrite here.
Corrected syntax:
#Remove PHP extension from links
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /$1.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+php\ HTTP
RewriteRule ^(.+)\.php$ /$1 [R=301,L]