Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
957 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 Answer

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]
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...