Redirect with .htaccess



I am trying to fix a problem where Google has indexed the wrong version of a
URL. I need to redirect the bad version to the good version with 301
redirects.

I've tried a couple of things, but it's not working.

The bad URLs look like this:
/search.php?mode=search&narrow_cat=2&term=World,%20Hello&page=1

That should redirect to:
/dir/Hello_World

This one doesn't work at all:
RewriteRule
^search\.php\?mode=search&narrow_cat=[0-9]{1,2}&term=([A-Z]{1}[a-z]+),%20([A-Z]{1}[a-z]+)&page=1$
http://www.example.com/dir/$2_$1 [R=301,NC,L]


This one works, except it doesn't include the "Hello" and the "World", only
the underscore:

RewriteCond %{QUERY_STRING}
mode=search&narrow_cat=[0-9]{1,2}&term=([A-Z]{1}[a-z]+),%20([A-Z]{1}[a-z]+)&page=1$
RewriteRule ^search\.php http://www.example.com/dir/$2_$1 [R=301,NC,L]

Any ideas?


.



Relevant Pages

  • Is there anyway to make decisions in Htaccess.
    ... Is there any capability of decisions in htaccess. ... In other words I want to redirect the visitor to one of many pages via ... I need to put the random selection in a variable like $var then append ... RewriteRule happy http://www.othersite.com/$var ...
    (comp.lang.javascript)
  • Re: php and mod_rewrite?
    ... to redirect to /index.php?$2, ... figure out how to redirect the ?show=files request AND at the end add ... RewriteRule does not match against the query string in mod_rewrite. ...
    (comp.lang.php)
  • Re: mod_rewrite / comprehensive redirects
    ... RewriteRule ^\.php$ /new/index.html ... this rule matches nothing (or at least does not redirect). ... leave the rewrites alone. ... Paul Schmehl ...
    (freebsd-questions)
  • mod_rewrite / comprehensive redirects
    ... However, what I would really like to achieve is to redirect every php file to /new/index.html, which currently does not work. ... RewriteRule ^\.php$ /new/index.html ... Zbigniew Szalbot ...
    (freebsd-questions)
  • Re: Moving a web site: am I doing this right?
    ... The Redirect rules will not be used because RewriteRule already rewrote the request and redirected to your site. ... You will need to change the redirect lines to RewriteRules also, or somehow exclude them from the rewrite processing. ...
    (comp.infosystems.www.servers.unix)