我遇到了网址隐藏问题,从http://example.com/products/product.php
到http://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]
答案 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]