Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

2sweetworld's avatar

.htaccess redirect removing all query strings

I have a url like this; example.com/foo.htm?name=kdu (any query string)

I want to redirect to this page; example.com/blog/bar - completely removing anything after the question mark

Any idea, please?

0 likes
4 replies
Snapey's avatar

So you have a non-standard .htaccess file?

2sweetworld's avatar

I tried this, and it still won't work.

RewriteCond %{QUERY_STRING} .
RewriteRule ^/foo.htm(.*)$ /blog/bar/? [R=301,L]
siangboon's avatar

perhaps can consider simply do it in web route... it's flexible and easier...

Please or to participate in this conversation.