item.js
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* Created by TaoHuang on 2017/2/21.
*/
'use strict';
const helpers = global.yoho.helpers;
const TYPE = require('../type');
const MOBILE_DOMAIN = '//item.m.yohobuy.com';
module.exports = [
// 商品详情页老链接,形式一
{
type: TYPE.redirect,
origin: /^\/product\/pro_([\d]+)_([\d]+)\/(.*).html(.*)/,
target: (req, match, p1, p2, p3, p4) => {
req.mobileUrl = `${MOBILE_DOMAIN}/product/pro_${p1}_1/1.html${p4 ? p4 : ''}`;
return helpers.urlFormat(`/p${p1}.html${p4}`, null, 'item');
}
},
// 商品详情页老链接,形式二
{
type: TYPE.redirect,
origin: /^\/product\/pro_([\d]+)(.*)/,
target: (req, match, p1) => helpers.urlFormat(`/p${p1}.html`, null, 'item')
},
// 商品详情页老链接
{
type: TYPE.rewrite,
origin: /^\/p([\d]+).html(.*)/,
target: (req, match, p1, p2) => {
req.mobileUrl = `${MOBILE_DOMAIN}/product/pro_${p1}_1/1.html${p2 ? p2 : ''}`;
return `/product${req.url}`;
}
},
// 商品详情页新链接
{
type: TYPE.rewrite,
origin: /^\/([\d]+).html(.*)/,
target: (req, match, p1, p2) => {
req.mobileUrl = `${MOBILE_DOMAIN}/product/${p1}.html${p2 ? p2 : ''}`;
return `/product${req.url}`;
}
}
];