Nginx 重新導向正規表示式

Nginx 重新導向正規表示式

我有這個網址:

https://example.com/admin/catalog/product/view/id/45533/?___store=en_us&sendAttributionID=email_automation_5ffa6c5967af4527508858fb&ContactID=5f9d9eac1215fsdfsdfasdffsdfsdf04ff6c98af

我需要使用 nginx 將其重新導向到:

https://example.com/catalog/product/view/id/45533/?___store=el_gr&sendAttributionID=email_automation_5ffa6c5967af4527508858fb&ContactID=5f9d9eac1215fsdfsdfasdffsdfsdf04ff6c98af

事實上我需要從第一個連結:刪除

admin

並替換:

en_us

和:

el_gr

我現在有這個正規表示式:

rewrite ^/admin/(.*)$ https://example.com/$1 permanent;

這消除了行政單字。但我不知道如何更換

en_us

經過 UML 幫助後,現在我處於:

rewrite ^/admin/(.*?)en_us(.*?)$ https://example.com/$1el_gr$2 permanent;

在 Online Regex 中有效,但在 nginx 中無效

有什麼幫助嗎?

答案1

編輯

我首先認為僅更改正規表示式會有所幫助,如下所示:

rewrite ^/admin/(.*?)___store=en_us(.*)$ https://example.com/$1___store=el_gr$2 permanent;

但是,由於重寫匹配僅適用於“文件名”部分(最多?),因此它不起作用。需要一些其他技術。

相關內容