Possible Duplicate:
remove .php extension with .htaccess
I have
http://www.example.com/test/categoryform.php In my .htaccess file, how do I rewrite that to display as:
http://www.example.com/test/categoryform/ Possible Duplicate:
remove .php extension with .htaccess
I have
http://www.example.com/test/categoryform.php In my .htaccess file, how do I rewrite that to display as:
http://www.example.com/test/categoryform/ try this code out
RewriteEngine On # turn on the mod_rewrite engine RewriteCond %{REQUEST_FILENAME}.php -f # IF the request filename with .php extension is a file which exists RewriteCond %{REQUEST_URI} !/$ # AND the request is not for a directory RewriteRule (.*) $1\.php [L] # redirect to the php script with the requested filename and How to hide .php extension in .htaccess question is also usefull
In order to remove the trailing slash, you need to match it out in a condition
RewriteEngine On # make sure it's not a directory or a file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # match out the request URI without the trailing slash RewriteCond %{REQUEST_URI} ^/([^/]+?)/?$ # and see if it exists RewriteCond %{DOCUMENT_ROOT}/%1.php -f RewriteRule ^(.+?)/?$ /$1.php [L] But in order to get it to display (as in, it show up in the browser's address bar, you need:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+?)\.php RewriteRule ^(.+?)\.php$ /$1/ [L,R=301] Easy question asked a thousand times
RewriteEngine on RewriteBase /test/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php