简体   繁体   English

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

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

I have seen quite a few answers on how to redirect many URLs so that any .php extensions are removed, but this has been causing some troubles for me with conflicts. 我已经看到了很多有关如何重定向许多URL以便删除任何.php扩展名的答案,但这已经给我带来了一些麻烦。

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

I already am redirecting /quotes/1 /quotes/2 etc to /index.php?id=1 and /index.php?id=2 etc. But what I really want to do is simply match /random/ and have it point to /random.php and none of the existing answers seem to be that specific. 我已经将/quotes/1 /quotes/2等重定向到/index.php?id=1/index.php?id=2等。但是我真正想做的就是简单地匹配/random/并使其指向/random.php ,目前的答案似乎都不是那么具体。

Thanks. 谢谢。

To remove the .php extension with .htaccess use this: 要使用.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