Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do 301 redirects in .htaccess need to be in a priority order?

I have a site which has been redeveloped and the URLs are totally different. I've hundreds or 301 to do (the original URLs many were very long - I have no idea why) and I'm getting some funny results where some redirects are happening and others are redirecting, but to odd URLs. I was wondering if there is a specific order 301's need to go in. For example:

redirect 301 /News/Smart-Site-Waste-Management.aspx http://...
redirect 301 /News/tabid/96/tagid/68/damaged-doors.aspx http://...
redirect 301 /News/tabid/96/EntryId/91/Smart-Site-Waste-Management.aspx http://...
redirect 301 /News/tabid/96/EntryId/156/Plastic-Surgeon-hits-the-headlines.aspx http://...
redirect 301 /News/RepairoftheWeek/tabid/194/tagid/78/Gallery/RepairoftheWeek/tabid/194/EntryId/221/Scratched-laminate-floor-repair.aspx http://...

So my actual question is, should the "smaller" urls (the ones with less directory levels) be lower down this order and the more specific URLs be higher? My instinct tells me that if it's set as above, all those URLs will direct to the new link specified in the FIRST as they all start with "News/". This is what I am seeing in practice.

like image 382
user1245615 Avatar asked Mar 02 '12 17:03

user1245615


1 Answers

You need to place the most specific at the top and the least specific at the bottom. Also, make sure you're halting processing using [L] after each redirect rule to make sure apache doesn't process additional rewrite rules after it has found a rule that matches.

Could you please post your .htaccess file?

like image 109
Lior Cohen Avatar answered Sep 23 '22 15:09

Lior Cohen