Multiple 301 Redirect For Multiple Pages or URL

非 Y 不嫁゛ 提交于 2020-01-10 05:30:25

问题


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.

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?

Thanks a lot


回答1:


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

  1. Add following line to your httpd.conf file:

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

    somename nicecar
    blabla newpros
    
  3. Add these line in your .htaccess file under DOCUMENT_ROOT:

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



回答2:


If you have access to the vhost or server config, you can setup a rewrite map, though in reality, it's probably marginally faster than just having a ton of redirects. The redirects that you have in your htaccess file are cached, so as long as the htaccess file isn't modified, the directives don't need to be re-read.

There's a very detailed tutorial for how to use RewriteMap and the many various mappings you can use with it.



来源:https://stackoverflow.com/questions/18877075/multiple-301-redirect-for-multiple-pages-or-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!