'htaccess RewriteRule string with parameters to homepage

I need to rewrite url

mydomain.com/?view=article&id=288:article_name&catid=116

to

mydomain.com/

How to do that?

I tried

1.

RewriteRule ^?view=article&id=288:article_name&catid=116$ / [R=301,L]

No success.

2.

RewriteCond %{QUERY_STRING} ?view=article&id=288:article_name&catid=116
RewriteRule .*$ /? [L,R=301]

When i test i get "We failed to execute your regular expression, is it valid?" on RewriteCond.



Solution 1:[1]

RewriteCond %{QUERY_STRING} ?view=article&id=288:article_name&catid=116
RewriteRule .*$ /? [L,R=301]

The QUERY_STRING server variable does not itself contain the ? prefix. However, ? is a special meta character in the regex (2nd argument to the RewriteCond directive) so this is not valid.

The RewriteRule pattern .*$ also matches everything, yet your example is the root only.

Try the following instead:

RewriteCond %{QUERY_STRING} ^view=article&id=288:article_name&catid=116$
RewriteRule ^$ /? [L,R=301]

Test first with a 302 (temporary) redirect to avoid potential caching issues and make sure you've cleared your browser cache before testing (301s are cached persistently by the browser by default).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrWhite