Author Topic: Max Htaccess redirects number  (Read 2361 times)

ukgimp

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2241
    • View Profile

ergophobe

  • Inner Core
  • Hero Member
  • *
  • Posts: 9279
    • View Profile
Re: Max Htaccess redirects number
« Reply #1 on: October 18, 2018, 04:53:58 PM »
That's kind of funny... but he's missing a couple of pieces.

Based on his numbers, he is testing this over a fast, low-latency connection. Another thousand redirects aren't a problem there. The problem is over 3G, satellite, etc. where you can easily add 300ms per hop on 3G and double that for satellite.

If you live where I live and 4G is commonly referred to as Faux G, lots of latency there too.

If the redirect involves a DNS lookup, you can double that. So if you redirect the page and you have a lot of redirects for resources too, then it starts to add up over a high-latency connection.

Quote
Top tip for using 1:1 redirects: place them last in the file because if the redirect is handled by a regex statement with a last tag, the 1:1 rules won’t be parsed. Problems are easier to diagnose that way.

Actually, I think this is exactly wrong. The problem with this is that the regex matches are going to handle general redirects (http to https, non-www to www, fixing case in Windows, directory moves and so forth).

I went round and round and round with a developer on this a couple years ago trying to explain that you want your redirects in order of decreasing specificity. His redirects were like this

1. http to https
2. non-www to www
3. mixed case to lower case
4. strip extension
5. old page to new page

That meant that if you had a request for http://example.com/OldPage.aspx it would take 5 hops to get to the right address, at least one of which (non-www to www) requires a DNS lookup.

I finally just had to learn how to speak IIS and write the redirects for him. My principle is that it should take only one redirect to get to the destination. His code was just plain stupid, but if you follow the advice in the SEO Mike article, it is inevitable that you will make two hops.

So to me the rules should be

1. http://example.com/OldPage.aspx to https://www.example.com/newpage

Now I'm done. I never match the following regex-based rules. And every regex-based rule should be a complete rewrite. The only way I can ensure I always get only one hop is if I put my single-line redirects at the top, then get increasingly general as I go down.

With SEO Mike's practice, there is no practical way to get from  http://example.com/OldPage.aspx to https://www.example.com/newpage in a single hop.

buckworks

  • Inner Core
  • Hero Member
  • *
  • Posts: 1633
    • View Profile
Re: Max Htaccess redirects number
« Reply #2 on: October 18, 2018, 05:03:55 PM »
I'll be back later.

I gotta go rearrange some .htaccess files.

ergophobe

  • Inner Core
  • Hero Member
  • *
  • Posts: 9279
    • View Profile
Re: Max Htaccess redirects number
« Reply #3 on: October 18, 2018, 05:30:16 PM »
Well Bucky, if you're doing that, let me add a little detail to this

Quote
And every regex-based rule should be a complete rewrite.

In the example I gave above, they are all similarly specific, so there's no logical order. The key is that any given redirect is sufficient to eliminated the need for the next one.

So when you redirect from http to https, make sure you also make the transformation from non-www to www (or the reverse), to set case (if applicable - Windows servers only), remove the extension, etc.

When you redirect from www to non-www, you want to fix the protocol, case, extension, etc at the same time, and so on.

You can do this with a series of RewriteRule that either will or won't match and rewrite, or a series of RewriteCond linked with OR and a single RewriteRule. At that point, if there is any difference at all, you are truly optimizing for a couple of ms and your big performance gain would come from moving these out of .htaccess and putting them into httpd.conf... or moving off Apache onto something else entirely.

The key is avoiding multiple hops for users on high-latency connections.
« Last Edit: October 18, 2018, 05:32:25 PM by ergophobe »

martinibuster

  • Inner Core
  • Full Member
  • *
  • Posts: 180
    • View Profile
    • Email
Re: Max Htaccess redirects number
« Reply #4 on: October 18, 2018, 06:34:19 PM »
Tom,
I'm a little confused. I think I viewed his experiment differently. Maybe I'm misinterpreting Mike's experiment?

What I understood was that Mike was testing how many lines of 1 to 1 redirects in an htaccess file does it take to slow a site down. Which would be different from redirecting the same URL thousands of times.


ergophobe

  • Inner Core
  • Hero Member
  • *
  • Posts: 9279
    • View Profile
Re: Max Htaccess redirects number
« Reply #5 on: October 18, 2018, 07:38:54 PM »
Thanks! Actually, I was wrong on multiple counts. Reading too fast. He actually agrees with me. He gives the quote I gave above and that's what I keyed in on, but at the end he says

Quote
It’s just not reasonable to say “Don’t use 1:1 redirects in an htaccess file because it’ll slow down the site.”

So actually, my only disagreement was that he could have taken it a step further and added how the received wisdom he quotes at the beginning is actually bad advice.

As his results show, parsing those single-match redirects doesn't take much time. It takes 100,000 of them to have a 300ms impact.

But if you do your redirects according to the advice he quotes (regex then 1:1), you will almost always incur at least three hops for a www to non-www redirect and old page to new page. So that means that means that you burn and extra 600ms (good, non-overloaded 3G or Yosemite Faux Gee) to 1200ms+ (satellite) in order to save 300ms.

So to hit breakeven for a 3G user, you need something on the order of 200,000 lines of redirects to make up for the extra hops.

Ideally, you would do the custom single-line redirects first, then catch what you can with increasingly general regex, otherwise you end up with chained redirects and those cost you way, way more over slow connections than parsing through your single-match redirects to get to your regex.

So double wrong:
1. Yes, he's really measuring parse time, even though he talks about TTFB and page load (that's what drew my astray)
2. The advice he quotes at the top is bad, but his conclusion is good, but a little incomplete
« Last Edit: October 18, 2018, 07:50:21 PM by ergophobe »