2017-02-10 27 views
0

有沒有更好的(更便宜)的方式來做到以下幾點?位置正則表達式 - 更好的方式?

location ~ \/..-..\/account\/(\bdeath-star-canteen\b|\bcake-or-death\b|\bcovered-in-bees\b) { 
      return 301 https://www.example.com/example/expired-account; 
    } 

應符合:

http://www.example.com/en-gb/account/death-star-canteen 
http://www.example.com/en-gb/account/cake-or-death 
http://www.example.com/en-gb/account/covered-in-bees 

,並將其重定向到一個過期的帳戶頁面? en-gb可以根據語言環境而有所不同?

此外,它需要轉義/在nginx的URL正則表達式?

回答

1

這不是真的很貴,或者你應該澄清一下昂貴的手段在這種情況下,但有一個更好的方式做到這一點:

location ~ /..-../account/(c(ake-or-death|overed-in-bees)|death-star-canteen) { 
    return 301 https://www.example.com/example/expired-account; 
} 

no need to escape slashes

+0

對於爲每個請求添加不必要的處理,我使用的代價很高。 – SpooForBrains

相關問題