Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

Fix Your Permalinks

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers.

There was a Tweet that was going around today:

[blackbirdpie id=”60389972049543168″]

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.

  • Shawn Collins
    Posted April 19, 2011 2:26 pm 0Likes

    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

Your email address will not be published. Required fields are marked *

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