Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
964 views
in Technique[技术] by (71.8m points)

.htaccess - Multiple 301 Redirect For Multiple Pages or 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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...