简体   繁体   中英

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.

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.

Thanks.

To remove the .php extension with .htaccess use this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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