5

I'm using mod_rewrite to process variables in the URL. For many of my URLs the final portion of the string doesn't matter because I'm not using it. For instance:

/review/company-25/jb-hunt

I'm only using the "company-25" portion to tell me which company is being requested (company # 25). The "jb-hunt" portion isn't needed. It's only to make a pretty URL for SEO purposes or whatever.

Well sometimes the final portion of the string might be wrong but I know what page they're requesting. For instance, someone links to my site with a typo. They meant to link to:

/review/company-25/jb-hunt

But they accidentally linked to:

/review/company-25/jbhunt

I know they want company #25 but the URL is wrong. How should I handle this?

From a user's standpoint I should probably redirect them to the correct page instead of issuing a 404. This is easy to do.

But what about from an SEO standpoint?

  1. Would a 301 redirect be the way to go even though the page being requested never existed?

  2. Should I show the page anyhow using the wrong URL but use a canonical tag to point search engines to the correct URL? (probably not)

  3. Should I issue a 404 and say the heck with the user experience? (probably not)

  4. Can I issue a 404 for the original request but then redirect the user to the correct page without them even knowing that the original was a 404?

What's the best way to handle this?

4

tl;dr You should 301 redirect to the canonical URL. This is for the benefit of SEO, as much as user experience.

You already know the correct resource to return (based on the company-25 part of the URL), so returning a 404 instead of correcting the URL seems a bit of a waste (and wasted SEO). Since you must already be doing the necessary lookups server-side in order to determine the slug is not as expected.

  1. Would a 301 redirect be the way to go even though the page being requested never existed?

Well, the page does exist (based on the ID part of the URL). But the URL is mistyped - so correct it.

  1. Should I show the page anyhow using the wrong URL but use a canonical tag to point search engines to the correct URL? (probably not)

The canonical tag gets around the duplicate content issue. And search engines should return the canonical URL in the results. However, a redirect is a far stronger signal and prevents the invalid URL being propagated by users. Just redirect.

  1. Should I issue a 404 and say the heck with the user experience? (probably not)

And the heck with SEO? You know the correct URL - just redirect.

  1. Can I issue a 404 for the original request but then redirect the user to the correct page without them even knowing that the original was a 404?

Messy, difficult/impossible to implement properly. If you issue a 404 then you can't issue a 3xx status as well. It would need to be a JavaScript (200) redirect. Users and search engines will see the 404 first.

Incidentally, this is what StackExchange does (ie. redirect incorrect slugs). The added benefit is that when titles change and hence the URL slug changes, the page automatically redirects to the canonical URL.

  • Thanks a ton for all of that. So when you say I should redirect the incorrect url to the correct one I'm assuming it should be a 301? It's definitely not a 302 and I don't want it to issue a 200 in the header for a url that doesn't exist. So just give em a straight up 301 and be done with it? – user2044510 Nov 1 '17 at 12:45
  • 1
    Yes, a 301 (permanent) redirect. It's a mistyped URL - which is never going to be the real URL - so a permanent redirect (that is cached by browsers and recognised by crawlers) is the way to go. – MrWhite Nov 1 '17 at 12:54
  • 1
    Excellent. Thanks. I've implemented this and it's working great. I had some RewriteRules that were too loose and they created a ton of duplicate content issues. Now I'm going through the site and fixing everything up. – user2044510 Nov 1 '17 at 14:20

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.