ghost
ghost

Reputation: 477

How to remove file extension (.php) using .htaccess

I want to rewrite

www.example.com/story.php?id=123&title=abc&cat=sports

to

www.example.com/story/123?title=abc&cat=sports

and i have used

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

its not working.

Upvotes: 2

Views: 75

Answers (1)

hjpotter92
hjpotter92

Reputation: 80629

RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /(story)\.php\?id=(\d+)&(\S+) [NC]
RewriteRule ^story\.php$ /%1/%2?%3 [R=301,L]

RewriteRule ^(story)/(\d+)/?$ /$1.php?id=$2 [L,QSA]

The above rules should work as needed.

Upvotes: 1

Related Questions