1

I know that hyphnes are preferred to underscores, and I could do a 301 redirect. But some say it's not worth the chaos to change them and I pretty much agree. https://moz.com/community/q/hyphens-vs-underscores

So, my urls look like this:

example.com/post/this-is-post-title_tokenid/

For new posts I will have:

example.com/post/this-is-post-title-tokenid/

I'm assuming I'd have to return a 404 in case of:

  1. new post with an undescore
  2. old post with a hyphen

Is this the right approach?

Or maybe I should do nothing and leave it as it is?

What would you recommend?

  • 1
    Is it literally just a single underscore before the tokenid (as in your example)? (And what format does the tokenid take?) Or could underscores be littered throughout the original URL (as in the thread you link to)? – MrWhite Nov 9 '17 at 11:32
  • "It is not worth the chaos of changing them" but your plan is to change them and not put redirects in place????? Not changing them would be leaving the underscores. If you are going to replace the underscores with hyphens and you don't want your SEO to suffer, you need to put in the redirects. – Stephen Ostermiller Nov 9 '17 at 11:40
  • 1
    @StephenOstermiller The question is confusingly worded, but the OPs plan is to not change them. The underscore stays as an underscore in the old URLs. ("new post with an underscore" will return a 404, because new posts don't have underscores. And "old post with a hyphen" will return a 404 because old post's don't have a hyphen (before the tokenid) - it looks like the OP is just stating the obvious? In this case no redirect is necessary, because the URL has not been changed! It seems to be a bit of a non-question, since the decision to not change the URL has already been made it seems.) – MrWhite Nov 9 '17 at 12:22
  • I see. Supporting two different URL styles based on the age of the post sounds like a nightmare to me. It would be easier to change the old ones in that case. – Stephen Ostermiller Nov 9 '17 at 12:47
  • 1
    What would be the purpose of doing all this work, fretting and concern since it means nothing to anybody? – Rob Nov 9 '17 at 13:41
2

It's not a major problem if you have some underscores, Google and Bing have come along way since they first launched. If you want to be politicly correct then you can rewrite underscores to hyphen by editing the .htaccess with something like this:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule !\.(html|php)$ - [S=6]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=underscores:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=underscores:Yes]

RewriteCond %{ENV:underscores} ^Yes$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

If you would rather use PHP then you can rewrite the URLS using a replace e.g using: $input_uri = $_GET['rewrite_uri']; and $output_uri = str_replace("_", "-", $input_uri); etc.

0

Back in the day it was best practice to use only dashes in URL's. Underscores were often used in image/file names (because, OS). But now bots are not so nitpicky.

I would do nothing and leave it as it is. Your token is not a relevant index focal, so the char before it is irrelevant anyways. It's not worth changing the archive stuff simply because of an underscore. For the new stuff, it's purely a matter of how you want the URi to look. Modern SEO indexers don't really care if one char is an underscore/dash, they just need to see the words. Personally, I would keep the underscore, since it acts more like a divider between your post and the token.

  • "bots are not so nitpicky" -- even today Google doesn't treat the underscore as a word separator, but it does so for the dash. Google reps have spoken about this and feel that it just isn't worth the hassle for Google to fix, so it will probably stay that way. Your advice about leaving things as is with the underscore is good, but for the reason that Google doesn't appear to weight words in the URL very much at all these days. – Stephen Ostermiller Nov 9 '17 at 20:35

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.