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.

4
  • 1
    Use a RewriteCond to match query string Commented Mar 22, 2022 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? Commented Mar 22, 2022 at 14:30
  • Thank you. It seems that everything should work with rewritecond.. But it doesnt. Commented Mar 22, 2022 at 14:40
  • 'When i test i get "We failed to execute your regular expression, is it valid?"' - Where are you seeing that response? Commented Mar 22, 2022 at 15:20

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.