Should 301 redirects in .htaccess be prioritized?

I have a website that has been redesigned and the URLs are completely different. I need to do hundreds or 301 (many of the source URLs were very long - I have no idea why), and I get funny results when some redirects happen and others redirect instead of the odd URLs. I was wondering if there is a need for a specific order of 301. 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 (those with fewer directory levels) be reduced below this order, and more specific URLs will be higher? My instinct tells me that if it is installed above, all these URLs will be redirected to the new link specified in FIRST, since they all start with "News /". This is what I see in practice.

+4
source share
2 answers

You need to place the most specific at the top and the least specific at the bottom. Also, make sure you stop processing with [L] after each redirection rule, to make sure apache does not process additional rewrite rules after it finds a rule that matches.

Could you post your .htaccess file?

+3
source

Ordering is only relevant if there are several matching lines (for example, if you also use RedirectMatch or mod_rewrite RewriteEngine On , which can interact with redirection directives.

In the htaccess file, you will come across a strong effect analyzing 100 rules, especially if the match speed is now slow. If your current URIs do not start with / News, then a good trick is to move all these redirects to DOCROOT/News/.htaccess , as this will only be parsed for URI / News / .... and therefore from any another URI path.

0
source

Source: https://habr.com/ru/post/1399435/


All Articles