17

I have a Joomla 3.3.6 (edited: 3.5.) site organized in only 3 levels:

  • Four big categories (i, ii, iii, iiii)
  • Each one divided in some intermediate categories (A, B, C, ...)
  • And finally articles
  • Two languages (en, pt)

The URL after setting Search Engine Friendly URLs, Use URL rewriting, Adds Suffix to URL and multilanguage support, should be in the form:

http://www.example.com/en/bigcatiii/intercatA/articlex.html

But as many others that have Joomla installed and ask for a solution since Joomla-Baby-Version, I got:

http://www.example.com/en/bigcatiii/666-intercatA/articlex.html

where 666 is a number from hell indicating for no purpose a category ID

Now browsing for an answer, I found this answer:

 Edit “components/com_content/router.php“
 (You’ll probably have to re-do this step every time you update Joomla.)
 Replace the lines 38 and 290 with:
 $advanced = $params->get('sef_advanced_link', 1);

 and Replace line 426 with
 ->where($db->quoteName(‘alias’) . ‘ = ‘ . $db->quote($segment)); 

Well, first of all, line 426 is already like that in the original. Second, this does not do the trick. It do works with:

http://www.example.com/en/bigcatiii/intercatA/articlex.html

But it breaks wit a 404 error if you browse to:

http://www.example.com/en/bigcatiii/intercatA.html

Also, I noticed that the ID numbers are different. While the whole URL is

http://www.example.com/en/bigcatiii/666-intercatA/articlex.html

The same category description page is

http://www.example.com/en/bigcatiii/333-intercatA.html

There is also another solution that sound better, but also do not work, based on .htaccess

RewriteEngine on
RewriteBase /
RewriteRule (\d+)-([^/]*) $2 [R=301,L]

The URLs appear ok, but the pages are not found. It would be so much better if we can provide a solution using .htaccess instead of changing Joomla core.

Still, changing the Joomla core would just fine, if this other googled suggestion was valid.

 Copy “components/com_content/router.php” to “/templates/your-template/html”

Meaning that once you moved router.php to your "local", you wouldn't need to redo all the stuff after an upgrade. (Unless, of course, router.php is updated, in case you would better mirror it again.)

Thanks for your time to solve this puzzle!

References

1- Change/ Remove Article ID in URL?

2- Removing the Article ID number

3- How to remove article id in url?

4- Remove article id from url for joomla 3.0

5- Enabling SEF

6- Remove article id from joomla 3 URL

7- Remove article id from joomla 3 URL

8- .htaccess redirect rule

9- Test .htaccess


Edited (2016/May/02): NEW Bounty for Joomla last version 3.5

Community
  • 1
  • 1
DrBeco
  • 11,237
  • 9
  • 59
  • 76
  • Looking forward to find a gentle soul who has the answer... – DrBeco Oct 08 '14 at 18:04
  • After several weeks waiting for some answer, the bounty was dropped and restarted again (automatically). Now with only 4 hours to award the bounty, I don't have my Joomla with me and there is no time to check if this answer meets the requirement. So, regarding the precision of the unchecked answer, I decided to award the bounty in the merit of the effort. If that turns out to be wrong, I'll ask the author to edit. If other better answer follow in the next days, I can change the accepted answer only. Thanks a lot for your effort, @achedeuzot. – DrBeco Oct 13 '14 at 00:20
  • I'm waiting for a better answer now. Is this still a problem? Is there a better, simple, solution? – DrBeco Mar 24 '15 at 02:42
  • Is this answer still ok for Joomla 3.4? Is there a better solution? – DrBeco Aug 24 '15 at 01:47
  • have you posted this in joomla.stackexchange.com? you might find a joomla specialist more able to respond. – pathfinder May 02 '16 at 15:59
  • Thank you @pathfinder, but I didn't. I hope this question here gets a good update. – DrBeco May 02 '16 at 18:15
  • I'm afraid in 14 hours the bounty will expire with no more answers added here. :( – DrBeco May 09 '16 at 01:40

4 Answers4

2

I've just newly installed a joomla 3.5 and the old method works for me. Since something has been modified in the router file, you have to repeat the procedure after a joomla upgrade.

The lines are now 34 and 295 in ./components/com_content/router.php.

Again change the 0 into 1 so that it becomes:

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


My URL is e.g. http://joomla.lan/en/category-en-gb/article-en-gb works fine with Search Engine Friendly URLs on.

With Adds Suffix to URL switched to Yes an .html is appended to the URL.
Use URL Rewriting and Unicode Aliases work optionally. When using URL rewrite engine on IIS7 or Apache, you have to rename htaccess.txt into .htaccess and webconfig.txt into webconfig. Note that some hosters have a restrictive server configuration. If you get a 500 internal server error, you might need to edit .htaccess and comment out the lines Options +FollowSymlinks and/or Options -Indexes and/or RewriteBase / by adding a preceding #. The latter is already deactivated in Joomla 3.5. A RewriteBase setting is useful when Joomla is installed in a subfolder, not the web root.

On other servers set Use URL Rewriting to No.


I can't reproduce your problem, everything is working correct with those two code edits. Please try it out again and if you can't resolve, post the exact behavior (urls, errors aso.) If you can not get it fixed, you might have to reinstall the sources.

Pinke Helga
  • 6,378
  • 2
  • 22
  • 42
  • Thank you for your time and effort to help answer this issue. I'll grant you the bounty (before it expires) based on your explanation, but I'll not set it as accepted answer yet. I believe that if what you say holds, I'll keep the old answer as accepted. Tx again. – DrBeco May 09 '16 at 18:00
  • As you stated, you are using URL rewrite engine, what's a good thing on IIS7 & Apache. Did you remember to rename `htaccess.txt` into `.htaccess`? I'add this point to the answer. – Pinke Helga May 09 '16 at 18:40
1

After looking into it, I found some useful pieces of information. DISCLAIMER I don't use Joomla and haven't tried this on a working installation, these are only results of some searching & reading source code. Anyway, here's what I found.

From what I have gathererd, it seems that changing

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

to

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

should be enough. Be careful though, with this option, probably both URL (with and without IDs) will be available which isn't good for SEO. Problem is with the 404, but that seems like a problem with the Joomla routing system. You could compensate the 404s with menu links which are only configured but never used (see below).

Some origins of your problem:

  • For example, in their routing, they use the menu to find the category ID (Line ~385 // We get the category id from the menu item and search from there)
  • For each URL segment (separated by the /), they first search category aliases, so be sure to check your aliases. If they cannot find the alias in the categories, they rely on the ID in the URL for their search query (Line ~425 ->where($db->quoteName('catid') . ' = ' . (int) $vars['catid']))
  • When a categoryID or articleID is attached to a menu, they remove the category ID $query['catid'] because they know they have a unique global alias (Line ~69)

Therefore, one solution is to do the following:

You could try and create a menu item for each category and each article. Even if the menu is not displayed anywhere and only configured in the administration interface, it will create global unique routing aliases for categories and articles which will let Joomla find the right article/category. From what I understand, when a category or article has a menu item, then only the title aliases are used. But since they don't have any, they use the combination of id + slug to locate the resource.

Since a lot of people are complaining about this, it should be fixed in Joomla 3.5

References & Discussions:

To finish on a bright note, it seems that the developers are aware of the limitations ;)

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
achedeuzot
  • 4,164
  • 4
  • 41
  • 56
  • Well, thank you! Now, in your understanding, if I GUARANTEE that my category aliases are all different from each other, can you provide a simple hack that would allow Joomla to work UNDER THIS USER GUARANTEE? (I know that that solution wouldn't be something we would see in the main truck of Joomla 3.5, because you cannot let this responsibility to the user, but as a workaround, I'll take this responsibility myself while the new version is not available) – DrBeco Oct 12 '14 at 23:15
  • I'm not sur I understand your question but you have two possibilities: create a hidden menu with the unique aliases so Joomla has this "Lookup table" or you could try "forecefully" unsetting the `catid` in the router but you'd have to test explicitly to make sure it doesn't brake anything else. I'm sorry I don't have an installation at hand to test it out though and I'm far from a Joomla specialist ;) – achedeuzot Oct 12 '14 at 23:37
  • It's not working in Joomla 3.4.1. I need remove only the first ID, from category. – Mardzis Apr 02 '15 at 09:12
  • THe basic issue is this problem of duplicate names of subcategories and ALL content types (not just articles, any content you ever create with any component) . If you guarantee that you will never duplicate these you can make unique urls. The problem is that it is extremely hard to check for uniqueness among all the separate tables. The good thing is that within each category branch you are guaranteed unique category name so with 2 category levels it is guaranteed unique. This is why the whole thing needs to be rewritten or else you need to use an SEO component. – Elin Dec 21 '15 at 02:07
1

Joomla 3.7(?) to 3.10.5 Legacy router issue fix

Here is the solution that worked for me, on Joomla 3.10.5, but it might be the same from 3.7 up (If not fixed in 4.0).

Legacy router - path: @www/components/com_content/helpers/legacyrouter.php

Hacking the legacy router, and deactivate appending the category id to the segments array by commenting out line 199 in the legacy router and replacing it like this:

//if (!$advanced && count($array))
if (false)

Tried these solutions

And more: The site article urls only needed the category id to be removed, not the article id, as removing both causes a 404

Hoping this helps someone not have to spend the large amount of time I have trying .htaccess routing, other solutions and plugins before resorting to this hack.

You can see the result here: https://new.ac-news.org (under construction)

  • Thank you. To be honest, I gave up Joomla 7 years because of this problem. It was a deal breaker for me. But your answer is important, as others may come here to find a solution. – DrBeco Feb 08 '22 at 20:09
0

Another easy solution is to create a menu item as category blog and use the alias as your category.

It won't delete the URL in your website but you can still send the XML site map to your search engine without those categories URL with Id's