302 redirect url with parameters

强颜欢笑 提交于 2020-06-28 03:35:31

问题


In htaccess file the following works

redirect 302 /old.php http://somesite.com/new.php

but following fails

redirect 302 /old.php?this=that http://somesite.com/new.php

I think it's because the second version contains a query string. How can we redirect URLs like that?

Please note the destination URL format is different so it cannot be an automated rule, so I need to write the custom URLs that users will be redirected to.

I found a similar question with replies here, but the proposed solutions do not work:

.htaccess not able to redirect url

Thank you


回答1:


You may use this rule as topmost rule in site root .htaccess of old domain:

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)this=that(?:&|$) [NC]
RewriteRule ^old\.php$ http://somesite.com/new.php? [R=301,L]


来源:https://stackoverflow.com/questions/62423283/302-redirect-url-with-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!