Authored by 周少峰

channel seo url

... ... @@ -11,10 +11,8 @@ const _ = require('lodash');
const channelModel = require('../models/index');
exports.index = (req, res, next) => {
let channelType = req.path.substring(1) || 'boys';
let channelType = req.path.split('/')[1] || 'boys';
// 将woman转换为girls,以便model层进行处理
channelType === 'woman' ? channelType = 'girls' : null;
channelModel.getContent(channelType).then(data => {
// channel为空不缓存
... ... @@ -91,3 +89,11 @@ exports.hasNewUserFloor = (req, res, next) => {
res.send(data);
}).catch(next);
};
// 频道页301重定向
exports.redirect = (goUrl) => {
return function(req, res) {
res.redirect(301, goUrl);
};
};
... ...
... ... @@ -6,7 +6,7 @@
'use strict';
const router = require('express').Router(); // eslint-disable-line
const router = require('express').Router({strict: true}); // eslint-disable-line
const cRoot = './controllers';
// Your controller here
... ... @@ -14,9 +14,12 @@ const channelController = require(`${cRoot}/index`);
// 频道页路由
router.get('/', channelController.index);
router.get('/woman', channelController.index);
router.get('/kids', channelController.index);
router.get('/lifestyle', channelController.index);
router.get('/woman', channelController.redirect('/girls/'));
router.get('/girls/', channelController.index);
router.get('/kids', channelController.redirect('/kids/'));
router.get('/kids/', channelController.index);
router.get('/lifestyle', channelController.redirect('/lifestyle/'));
router.get('/lifestyle/', channelController.index);
router.get('/japanKorean', channelController.japanKorean);
router.get('/channel/isNewUserAjax', channelController.hasNewUserFloor);
... ...
... ... @@ -296,7 +296,7 @@ const getPackage = (req, res, next) => {
};
const redirectNewProduct = (req, res) => {
return res.status(301).redirect(helpers.urlFormat(`/product_${req.params[0]}${req.params[2]}`, null, 'item'));
return res.redirect(301, helpers.urlFormat(`/product_${req.params[0]}${req.params[2]}`, null, 'item'));
};
module.exports = {
... ...
... ... @@ -19,8 +19,10 @@ module.exports = () => {
switch (req.subdomains[0]) {
case 'www': // 主站
case 'cdnsrcwww': // 主站的回源地址
case 'new': // 原新版
case 'shop': // 商家入驻
break;
case 'new': // 原新版 重定向到301
return res.redirect(301, helpers.urlFormat(req.url, null, 'www'));
case 'item':// 商品详情页
if (/\/product_([\d]+)(.*)/.exec(req.url) !== null) {
req.url = `/product/product_${RegExp.$1}${RegExp.$2}`;
... ...