Eric Nagel

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:
http://www.independent.co.uk/life-style/food-and-drink/utter-PR-fiction-but-people-love-this-shit-so-fuck-it-lets-just-print-it-2269573.html

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);
	exit();
} // 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.