多301重定向对于多页或URL [英] Multiple 301 Redirect For Multiple Pages or URL

查看:214
本文介绍了多301重定向对于多页或URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我重新设计我的商店等老结构已经改变的新结构。因此,试图重定向所有老产品与新的。

I am redesigning my store and so the old structure has been changed with the new structure. So trying to redirect all old products with the new.

我有超过20-25的产品,如果我写的重定向规则的每一件产品不是我要这样写

I have more than 20-25 products and if I write redirect rule for every product than I have to write in this way

Redirect 301 /store/products/somename/ http://store.domain.com/nicecar
Redirect 301 /store/products/blabla/ http://store.domain.com/newpros
Redirect 301 /store/products/cubacuba/ http://store.domain.com/illollo

这将成为长和可能减缓的网站。所以,反正是有优化这个重定向规则?

Which will become to long and may slow down the site. So is there anyway to optimize this redirect rule?

多谢

推荐答案

这是更好地使用的 RewriteMap指令 您的需求。下面是一个例子如何使用它:

It is better to use RewriteMap for your requirement. Here is an example how to use it:

  1. 添加下面一行到你的的httpd.conf 文件:

RewriteMap prodMap txt://path/to/prodMap.txt

  • 创建一个文本文件作为 /path/to/prodMap.txt 是这样的:

  • Create a text file as /path/to/prodMap.txt like this:

    somename nicecar
    blabla newpros
    

  • 添加这些线在你的.htaccess文件在 DOCUMENT_ROOT

    Options +FollowSymLinks -MultiViews
    RewriteEngine on
    
    RewriteRule ^store/products/([^/]+)/?$ http://store.domain.com/${prodMap:$1} [L,R=301,NC]
    

  • 这篇关于多301重定向对于多页或URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆