繁体   English   中英

我如何仅使用.htaccess仅针对特定文件删除.php扩展名?

[英]How can I simply remove the .php extension using .htaccess only for a specific file?

我已经看到了很多有关如何重定向许多URL以便删除任何.php扩展名的答案,但这已经给我带来了一些麻烦。

RewriteRule ^quote/([a-zA-Z0-9]+)/$ index.php?id=$1
RewriteRule ^quote/([a-zA-Z0-9]+)$ index.php?id=$1

我已经将/quotes/1 /quotes/2等重定向到/index.php?id=1/index.php?id=2等。但是我真正想做的就是简单地匹配/random/并使其指向/random.php ,目前的答案似乎都不是那么具体。

谢谢。

要使用.htaccess删除.php扩展名,请使用以下命令:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM