joined:Apr 6, 2013
Rather than hijacking some other thread, I thought it'd be a good idea to start a new discussion about this.
On these forums, some have frequently conveyed a "rule" that every redirect should include the canonical hostname in the target. But I think this is a gray area with trade-offs.
The downside of not including the canonical in all redirects is that, in some circumstances, the user would go through an extra hop.
The downside if we do
include the canonical in all redirects is that we have to repeat it throughout our htaccess, and ideally we want our code to be DRY
I actually don't think either of these downsides is too terribly significant. Yes, there might be some repetition, but htaccess files are typically small, and search-and-replace should be able to deal with this easily. Or yes, there might be an extra hop, but these occurrences should be rare. All your internal links should already be canonical; people's bookmarks are highly likely to be canonical; etc. And
not only would the user have to visit through a non-canonical, but the URL they access would have to have other redirects associated with it as well.
I see validity in both options, and I don't think either is necessarily the "right" way.
Personally, I opt to not include the canonical in all redirects. My philosophy that led to this preference is this:
Write your code first and foremost for humans. Focus on readability and maintainability. Then profile your application to find the bottlenecks. Use that information to optimize smartly. Ideally, your code will be optimized for speed where it matters, and optimized for human maintainability everywhere else.
But I want to emphasize again that I see validity in both options. The point I want to make is that I think we do a disservice to other users here when we talk about this subject as if there's only one right way. I think we could better educate them if we were to tell them about the options and trade-offs.