如何从所有文件的 url 中隐藏 php 文件扩展名


How to hide php file extension from url from all files?

>我有很多php文件,但我坚持认为我想在所有文件的url中隐藏php扩展名,而无需编辑我的代码。另一个问题是网站使用 $_GET 从链接、标题、表单中捕获许多参数,有没有办法从 url 中隐藏参数,或者至少可以在不影响网站功能的情况下更改它的外观。

我试过这个但没有工作:

 Options -MultiViews
 RewriteEngine On
 RewriteCond %{THE_REQUEST} ' /+([^'?]+)'.php'?pid=([0-9]+)
 RewriteRule ^ /%1/%2? [L,R]
 RewriteCond %{THE_REQUEST} ' /+([^'?]+)'.php(' |$)
 RewriteRule ^ /%1 [L,R]
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{DOCUMENT_ROOT}/$1.php -f
 RewriteRule ^([^'.]+)/([0-9]+)$ /$1.php?pid=$2 [L]
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^'.]+)$ $1.php [NC,L]

试试这个:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

.htaccess 文件中尝试以下代码

# 开启重写引擎重写引擎打开RewriteCond %{REQUEST_FILENAME} !-f重写规则 ^([^''.]+($ $1.php [常闭,中]

谢谢。