Home > database >  htaccess RewriteRule string with parameters to homepage
htaccess RewriteRule string with parameters to homepage

Time:03-23

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.

CodePudding user response:

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

  • Related