Authored by 陈峰

fix seo 301

@@ -10,7 +10,7 @@ const helpers = global.yoho.helpers; @@ -10,7 +10,7 @@ const helpers = global.yoho.helpers;
10 const logger = global.yoho.logger; 10 const logger = global.yoho.logger;
11 const _ = require('lodash'); 11 const _ = require('lodash');
12 12
13 -// const handleFilterUrl = require(`${global.utils}/parameter`).fullParamToMinPath; 13 +const handleFilterUrl = require(`${global.utils}/parameter`).fullParamToMinPath;
14 14
15 // 搜索相关接口 15 // 搜索相关接口
16 const searchApi = require('../models/search-api'); 16 const searchApi = require('../models/search-api');
@@ -26,14 +26,14 @@ exports.index = (req, res, next) => { @@ -26,14 +26,14 @@ exports.index = (req, res, next) => {
26 let resData = {}; 26 let resData = {};
27 let qs = ''; 27 let qs = '';
28 28
29 - // if (req.originalUrl && req.originalUrl.indexOf('.html') < 0 &&  
30 - // req.originalUrl.indexOf('?') < 0 && !_.isEmpty(req.query)) {  
31 - // let rUrl = handleFilterUrl('/list', req.query); 29 + if (req.originalUrl &&
  30 + req.originalUrl.indexOf('.html') < 0 &&
  31 + req.originalUrl.indexOf('?') < 0 &&
  32 + req.yoho.seoParse) {
  33 + let rUrl = handleFilterUrl('/list', req.query);
32 34
33 - // if (rUrl !== req.originalUrl) {  
34 - // return res.redirect(301, helpers.urlFormat(rUrl));  
35 - // }  
36 - // } 35 + return res.redirect(301, helpers.urlFormat(rUrl));
  36 + }
37 37
38 try { 38 try {
39 qs = decodeURIComponent(req._parsedOriginalUrl.query || ''); 39 qs = decodeURIComponent(req._parsedOriginalUrl.query || '');
@@ -8,7 +8,12 @@ module.exports = (req, res, next) => { @@ -8,7 +8,12 @@ module.exports = (req, res, next) => {
8 param = _.trimEnd(param, '.html'); 8 param = _.trimEnd(param, '.html');
9 9
10 if (param) { 10 if (param) {
11 - Object.assign(req.query, parameter.minPathToFullParam(param)); 11 + const params = parameter.minPathToFullParam(param);
  12 +
  13 + if (Object.keys(params).length) {
  14 + Object.assign(req.query, params);
  15 + req.yoho.seoParse = true;
  16 + }
12 } 17 }
13 18
14 next(); 19 next();