簡體   English   中英

nginx根據來自uri的參數id重定向

[英]nginx redirect based on parameter id from uri

需要根據 personId uri 參數重定向。

https://server.com/de/prints/?personId=1重定向到https://anotherserver.com/dir1/dir2/dir3/dir4/dir5/the-result?statusId=1&personId=1

需要為每個 personId 值執行此操作,因此基本上如果請求是: https://server.com/de/prints/?personId=2將其重定向到https://anotherserver.com/dir1/dir2/dir3/dir4/ dir5/the-result?statusId=1&personId=2

我已經嘗試了以下方法,但它不起作用:

location ~* ^/de/prints? {
    if ($args ~* "personId=*") {
      rewrite ^.*$ https://anotherserver.com/dir1/dir2/dir3/dir4/dir5/the-result?statusId=1&personId=$1 redirect;
    }
}

為了在您的 URL 中使用$1 ,您需要使用括號(捕獲組)捕獲原始 URL 中人員的 Id。

.*[&?]personId=([0-9]+)而不是^.*$

這是一個演示: https : //regex101.com/r/yms4Oi/1

我設法使用以下方法使其工作:

location ~ /de/prints/ {
         if ($args ~* "personId=(.*)") {
             return 302 https://anotherserver.com/dir1/dir2/dir3/dir4/dir5/the-result?statusId=1&personId=$1;
         }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM