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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题