Moving the Article ID From the Beginning to the End of the URL in sh404SEF

While migrating a Joomla website from 1.5 to 2.5, we had an interesting issue: after we migrated the content and activated sh404SEF, we noticed that the IDs of the articles were at the beginning of the URL, instead of its end. For example, instead of this link:

http://www.ourclientjoomlawebsite.com/test-article-12345.html

We had this link:

http://www.ourclientjoomlawebsite.com/12345-test-article.html

Quick Note: 12345 is the article ID in our example above.

Clearly this is a huge issue and it needed fixing because all the URLs on the migrated website must be identical to those on the old website.

We dug through sh404SEF‘s settings, and we couldn’t find any setting to move the ID of the article from the beginning to the end of the URL. We knew then that there was only one way for doing this: Modifying sh404SEF‘s core!

After a really long time spent on exploring sh404SEF‘s code, we discovered that the code responsible for the placement of the article ID in the URL is in the file slugs.php which is located under the administrator/components/com_sh404sef/models directory. Here’s the code (lines 83-87):

if($insertId) {
	$separator = empty($separator) ? Sh404sefFactory::getConfig()->replacement : $separator;
	$slug = $id . $separator;
}
$slug .= $useAlias ? $rawArticle[$language]->alias : $rawArticle[$language]->title;

All that we needed to do was to replace the code above to:

$slug = $useAlias ? $rawArticle[$language]->alias : $rawArticle[$language]->title;
if($insertId) {
	$separator = empty($separator) ? Sh404sefFactory::getConfig()->replacement : $separator;
	$slug .= $separator.$id;
}

(Notice how we have moved the last line to the top, and how we removed the dot next to the equal sign from the last line to the line that was just above it.)

…and it worked! The article ID smoothly moved from the beginning to the end of the URL with no extra work on our end. We hope our work saved someone a lot of head scratching time!

Important note: Make sure you Purge all the URLs in sh404SEF‘s URL Manager after you make the above changes to the code. If you don’t then your changes will not apply to old articles.

OK – we now need to ask an important question: why is it that sh404SEF, the famous component that has a primary purpose of enhancing a Joomla website’s URLs for search engines, places the article ID in the beginning of the URL instead of its end?

We have no idea – especially because it’s much better, from an SEO perspective, to place the ID at the end rather than the the beginning of the URL. An odd decision indeed!

Now, if you have read this post but you don’t have the technical/programming skills to implement it – then fear not, we can help! Just contact us and we’ll do it for you in no time. Note that our very reasonable fees apply!

One Response to “Moving the Article ID From the Beginning to the End of the URL in sh404SEF”
  1. Pingback by How to Remove the Article ID from the Browser Title in sh404SEF | itoctopus — July 11, 2013 @ 10:33 am

    […] notice that everything works as it should (well, the ID of the article is in the wrong place, but we’ve already explained how to fix that), but you also notice something else. The ID of the article is, for some reason, in the browser […]

Leave a comment