我有一个很长的 URL,例如:
https://mydomain.com/post/api/v5/apps/123/events/viewitem?data={"h_Authorization":"Basic wfwe","p_itemId":"**2342342**","p_userId":"vt.user.1385032845751.407012548","p_sessionId":"vt.sess.51c01e03ed14d94e30000003.1385623645321.318345957","p_tracking":{"vt_medium":"site-recommender","vt_campaign":"51de83a46e68d16d71000faf","vt_content":"51de83a46e68d16d71000faf","vt_source":"site"},"q_templates":"51de844d63d9f3782a001009:51de844d63d9f3782a001009,51de83a46e68d16d71000faf:51de83a46e68d16d71000faf"}&callback=__vt_jsonp_1
并需要使用 nginx 将其重定向到
/公共/缓存/产品/2342342.json
所以,之前的部分2342342在原始 url 中它总是一样的,之后就无所谓了,因为它会被删除。
我尝试过:
location / {
rewrite ^/post\/api\/v5\/apps\/123\/events\/viewitem\?data={\"h_Authorization\":\"Basic wfwe\",\"p_itemId\":\"([0-9]+)(.*) public/cache/products/$1.json permanent;
}
并且不起作用。有什么办法可以修复它吗?
答案1
尝试这个:
rewrite ^/post/api/v5/apps/123/events/viewitem\?data=.*?p_itemId\"\:\"([0-9]+?)\".*?$ /public/cache/products/$1.json redirect;