在url中隐藏filename.php


Hiding filename.php in url

我在URL隐藏方面遇到问题,从http://example.com/products/product.phphttp://example.com/products/http://example.com/products/product/

我在htaccess中尝试过这段代码,但似乎不起作用。

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

要隐藏.php扩展,可以使用:

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]