phocks
phocks

Reputation: 3273

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.

Upvotes: 0

Views: 48

Answers (1)

Rizier123
Rizier123

Reputation: 59701

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

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

Upvotes: 1

Related Questions