BeeBee
BeeBee

Reputation: 31

Hiding filename.php in url

I am having troubles with URL hidding, from http://example.com/products/product.php to http://example.com/products/ or http://example.com/products/product/.

I have tried this block of code in htaccess, but it seems not to work.

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+)$ /$1.php [L,QSA]

Upvotes: 0

Views: 40

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

To hide the .php extension, you can use :

RewriteEngine on

#1)redirect  "/file.php" to "/file"
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [L,R]
#2)internally redirect "/file" to "/file.php"
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [L]

Upvotes: 1

Related Questions