How to Remove the Article ID from Joomla’s SEF URLs

If you’re not using a 3rd party extension to generate your SEF links, then most likely you are already annoyed by the presence of the article ID in article URLs. In fact, most Joomla administrators use a 3rd party SEF extension to generate their links instead of Joomla’s built-in SEF tool because of this particular problem.

So, is there a way to remove the article ID from the URL when using Joomla’s own SEF tool? The short answer is yes, but it requires a simple modification to a core Joomla file, which means that any update to your Joomla website may or may not break your link structure. If you’re not comfortable with this, then we suggest that you stop reading this post (or you can continue reading, who knows, we might have a surprise for you). If you’re OK with changing a core file on your Joomla site, then here’s how to do it:

  • Open the file router.php which is located under the /components/com_content/ folder.
  • Search for the following line (Joomla 3.3.x):

    $advanced = $params->get('sef_advanced_link', 0);

    and change it to:

    $advanced = $params->get('sef_advanced_link', 1);

    Note that the above line exists twice, and you must change it for both instances, or else your links will no longer work. (The links will stop working because the build and the parse functions in the router.php file will no longer be consistent with each other).

  • Save the file and upload it back.

  • Your links no longer contain the article ID. Congratulations!

As you can see from the above, the modification to the router.php is quite basic. Not only that, it seems that the com_content extension already has an option, sef_advanced_link, that automatically strips the article ID from the URL. Sadly, that option doesn’t exist anywhere in Joomla’s interface (it’s only retrieved in the router.php, but there is no way to set it in the configuration of the com_content extension), but we suspect that it will be added at a later stage.

So, is there really no other way but to change a core file?

Well, if you’re adventurous, then you can manually update the settings of the com_content extension in the database and manually create an sef_advanced_link parameter and set it to 1. Here’s how:

  • Login to phpMyAdmin
  • Select the database that powers your Joomla website.

  • Click on the #__extensions table.

  • Find the row where the name is com_content and open it in edit mode.

  • Add the following to the params field (just before the closing curly bracket):

    ,"sef_advanced_link":"1"

    (Note that the comma in the code above is not a typo, you should add it or else your website may malfunction).

  • Save the row.

  • Check your website (after clearing your Joomla cache), and you will notice that the article IDs are gone!

Both methods are not ideal, because for the first method the links will not work if the router.php file is updated, and, for the second method, the links will not work if you update the settings of the com_content extension through the backend (your hardcoded database changes will be wiped out).

Now, the question is, why does Joomla add the article ID to the URL in the first place?

Well, because if two different articles have the same alias, then adding the article ID to the URL will ensure that both URLs are different. However, we don’t think that this is a good excuse to force this option on Joomla websites, simply because Joomla can and does automatically generate a different alias for the second article that has the exact same title (it usually adds -2 to its end).

In this article, we have presented two ways to remove the article ID from article URLs, one by changing a file, and the other by changing a row in the database. As we have mentioned before, no option is optimal. If you’re not sure which option to implement, or if you feel that you this whole thing is not your game, then please contact us. We can help you do this in no time and for a very, very affordable fee!

2 Responses to “How to Remove the Article ID from Joomla’s SEF URLs”
  1. Comment by Scott Trsar — January 5, 2016 @ 7:17 pm

    This can be achieved in a simple system plugin. Following is the code that should be in that system plugin.

    /**
    * @event onAfterInitialise
    */
    function onAfterInitialise(){
    	/**
    	 * Advanced link
    	 *
    	 * Removes item id from auto-generated URLs
    	 * May cause issues if more than one item in the same group has the same alias
    	 */
    	JComponentHelper::getParams('com_content')->set('sef_advanced_link', 1);
    }

  2. Comment by Fadi — February 9, 2016 @ 6:37 am

    Hi Scott,

    Thanks for the solution. We have not tried it, but from the looks of it, it can work. I have to admit that your solution (if it works) is even better than our proposed solution because it doesn’t consist of a modification in a core Joomla file.

Leave a comment