0

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.

MrWhite
  • 43,179
  • 8
  • 60
  • 84
Aer
  • 49
  • 1
  • 12
  • 1
    Use a `RewriteCond` to match query string – anubhava Mar 22 '22 at 14:07
  • Please put in a bit of research effort, _before_ you automatically ask "how do I do that" as soon as someone mentions something new to you. [How can I match query string variables with mod_rewrite?](https://stackoverflow.com/questions/2252238/how-can-i-match-query-string-variables-with-mod-rewrite) – CBroe Mar 22 '22 at 14:30
  • Thank you. It seems that everything should work with rewritecond.. But it doesnt. – Aer Mar 22 '22 at 14:40
  • 'When i test i get "We failed to execute your regular expression, is it valid?"' - Where are you seeing that response? – MrWhite Mar 22 '22 at 15:20

1 Answers1

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).

MrWhite
  • 43,179
  • 8
  • 60
  • 84