How to remove ID from URL in Joomla 2.5-3.7

There is a new option in Joomla 3.8.2 allowing to get rid of ID in URLs (thanks to Ian who discovered it). If you have an older Joomla version and unable to update to 3.8.2 or higher follow the steps provided below:

Open components\com_content\router.php in an editor and make a small changes:

in function ContentBuildRoute(&$query) replace line 27

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

with

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

in function ContentParseRoute($segments) replace line 208

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

with

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

Comment out lines 228-232

if (strpos($segments[0], ':') === false) {
    $vars['view'] = 'article';
    $vars['id'] = (int)$segments[0];
    return $vars;
}

so it would be

/*
if (strpos($segments[0], ':') === false) {
    $vars['view'] = 'article';
    $vars['id'] = (int)$segments[0];
    return $vars;
}*/

That is all. I tested this on my Joomla 2.5.4 test site and looks like it works, but I cannot say that it works in all the cases.

Some explanation

If you tried the method described above and it works for you, you could leave it as it is and close this page, but if you interested in some explanation please read below.

As seen from lines 27 and 208 Joomla Content Component uses ‘sef_advanced_link’ parameter, so setting this parameter to ‘1’ eliminates the need for changing this lines. It could be done by adding the following XML to ‘fieldset’ section of administrator\components\com_content\config.xml:

<field name="sef_advanced_link"
    type="radio"
    default="0"
    label="Sef Advanced Mode"
    description="Remove ItemID from Content URL?">
        <option    value="0">JNO</option>
        <option    value="1">JYES</option>
</field>

and then setting ‘Sef Advanced Mode’ to Yes in ‘Article Manager Options’ window:

Remove ItemID from Content URL

Please note that setting default=”1″ in XML does not take an effect for some reason.

What concerns lines 228-232, if I leave them uncommented, ID disappears from URL and single articles open fine but when I trying to open a category not linked to some menu item I get “404 – Article not found” error message. I cannot say for sure, but I think that Joomla developers added ‘sef_advanced_link’ parameter but didn’t tested it well enough, so, probably, they will fix this code in future releases.

155 Responses to How to remove ID from URL in Joomla 2.5-3.7

Leave a Reply to Pete Lorocco Cancel reply

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