开发者

help with redirecting a specific page in nginx

I have been trying to do this for the last 4 hours and have searched everywhere. it would be great if you could help me开发者_开发知识库 with nginx rewrite rules.

I am trying to temporarily redirect hxxp://siteA/[dir] to hxxp://siteB/[dir] except for hxxp://siteA/?page=4 which I want to redirect to hxxp://siteB/?page=343

Here are the rules I have

server {
    listen 80;
    server_name siteA;
    rewrite ^/?page=4$ http://siteB/?page=343 redirect;
    rewrite  ^/(.*)$  http://siteB/$1  redirect;
}

But it seems to redirect hxxp://siteA/?page=4 to hxxp://siteB/?page=4 thus ignoring the first rule.

I have changed http to hxxp since I am not allowed to post links here.


A common problem faced when writing rewrite rules for web servers is assuming that query parameters are part of the script path.

Try matching the query parameters with a rule like the below before your 'main' rewrite rule:

if ($args ~ page=4){
  rewrite ^ http://siteB.com/?page=343;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜