在网址中隐藏filename.php

时间:2016-05-08 07:58:27

标签: php .htaccess url mod-rewrite url-rewriting

我遇到了网址隐藏问题,从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]

1 个答案:

答案 0 :(得分:1)

要隐藏.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]