Apr.19

Fix Your Permalinks

 
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.

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

Comments(1)

  1. Shawn Collins
    2054 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

Comment