301 redirect from URL with query string to new domain with different query string

后端 未结 2 538
感动是毒
感动是毒 2020-12-01 20:04

I am trying to figure out how to do a 301 redirect in my htaccess file to redirect some files to a new domain. Here\'s what I need to know how to do:

OLD URL: http:/

2条回答
  •  失恋的感觉
    2020-12-01 20:30

    I had the same problem, but still more complicated, because I needed to discard other parameters.

    Like this: my-old-page.php?a=1&b=2&c=3

    I need to use one of the strings and discard the others, but that solution only worked if I want to use the last parameter (c=3). If I want to use any other (a=1 or b=2) it runs to a 404. After much struggling and searching, I found an answer:

    RewriteCond %{QUERY_STRING}  ^.* ?b=2.* ?$ (without space after the *)
    
    RewriteRule (.*)  http://www.my-webpage.php/new-location-2?  [R=301,L]
    

    The solution is to add ".*?" before and after the parameter to use.

    I don't know if this is the best solution, but it works.

提交回复
热议问题