你好,我目前正在使用wampserver和此代码来删除文件扩展名。
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^'.]+)$ $1.php [NC,L]
是的,它正在工作,但是,我有很多php文件。有没有一种方法可以自动删除文件扩展名,而无需我将其从像<a href="index.php"> to <a href="index">
这样的href中删除?我也有像http://www.whatever.ph/index.php?pid=51
这样的链接,我希望它像http://www.whatever.ph/index/51
,或者什么是更好的链接
您可以进行一些全局搜索/替换来消除所有的.php扩展。你真的想更改html中的链接,否则你需要创建mod_rewrite规则,为每个有扩展名或难看链接的请求重定向浏览器。
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]