Fix Your Permalinks

There was a Tweet that was going around today:

This is what happens when u don't update a WordPress slug: RT @ Read the headline first, then the URL. http://ind.pn/gh7eB1
David Bisset

So the URL of the story was:

And the idea is that this was the WordPress title as the author composed the story, but then (of course) changed the title before publishing, but never updated the slug (permalink).

Well, that’s total BS, but a great story. What’s really going on is an SEO trick in which what comes before the number doesn’t matter at all, and is used to put keywords in the page name. I do the same thing with my datafeed sites – only I make sure if someone changes the keywords, it goes to the correct page. Simple enough fix:

$cPHPSELFExpected = '/' . simplify($rsMerchantData['cName']) . '-m' . $rsMerchantData['nMerchantID'] . '.php';
if ($_SERVER['REDIRECT_URL'] != $cPHPSELFExpected) {
	header("Location:  $cPHPSELFExpected", TRUE, 301);
} // ends if ($_SERVER['REDIRECT_URL'] != $cPHPSELFExpected)

I figure out what I expect the page to be, and if I’m not there, do a permanent redirect to the page I expect to be at. simplify() is a function I created to remove spaces & special characters, make things lowercase, and combine the phrase with dashes.

So if you’re running a datafeed site, make sure this little bit of code is in place to ensure your users are all seeing the same URL.

How To & Tips
Share this Story:
  • facebook
  • twitter
  • gplus


  1. Shawn Collins
    2801 days ago

    Thanks Eric – I just learned a useful tidbit, but at the expense of the enjoyment I got out of thinking that was authentic. 🙂

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.