donglu6805 2017-04-06 13:10
浏览 901

NGINX使用新参数将带有参数的URL重写到另一个URL

I want to redirect one specific URL with parameters as 301 to another specific URL with a new parameter.

https://www.example.com/index.php?id=329

to

https://www.example.com/index.php?eID=dd_googlesitemap

I tried something but I think there are several mistakes.

location = /index.php?id=329 {
    rewrite ^ https://www.example.com/index.php?eID=dd_googlesitemap permanent;
}

OR

location = /index.php {
    if ($arg_id = "329") {
        rewrite ^ https://www.example.com/index.php?eID=dd_googlesitemap permanent;
    }
}

OR

location = /index.php {
    if ($args ~ "id=329") {
        rewrite ^ https://www.example.com/index.php?eID=dd_googlesitemap permanent;
    }
}

Can anyone help?

Thanks!

  • 写回答

1条回答 默认 最新

  • dotxxh0998 2017-04-06 14:50
    关注

    The /index.php URI is processed by the location ~ \.php$ block, and includes all of the necessary statements to send the filename to PHP for execution. If you are going to create a new location for /index.php, you will need to duplicate these statements also.

    For example:

    location = /index.php {
        if ($arg_id = "329") {
            return 301 /index.php?eID=dd_googlesitemap;
        }
        ... php statements ...
    }
    location ~ \.php$ {
        ... php statements ...
    }
    

    Alternatively, check the URI before it enters a location block.

    For example:

    server {
        ...
        if ($request_uri = "/index.php?id=329") {
            return 301 /index.php?eID=dd_googlesitemap;
        }
        ...
    }
    

    See this document for more.

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试