Articles - Category in a module position creates multiple urls for one article

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
Morissius
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Tue Oct 31, 2017 7:41 pm

Articles - Category in a module position creates multiple urls for one article

Post by Morissius » Wed Dec 26, 2018 4:44 pm

Hey,

I decided to spend a little effort on SEO today. When I generated a sitemap with a component I noticed something odd. There were many different url's that pointed to the same article.

After some investigation it was discovered that the different url's originated from an 'Articles - Category' module shown on many pages; In the url the articles often include the page it originated from.

Example 1:

Code: Select all

www.somesite.com
would load
www.somesite.com/1-category/1-article
Example 2:

A slightly different url like

Code: Select all

www.somesite.com/contact
would load
www.somesite.com/contact/1-category/1-article
The desirable behavior should always output:

Code: Select all

www.somesite.com/1-category/1-article 
Somewhere in the relevant php file ( mod_articles_category/default.php ) I found out that the url is loaded by $item->link. That link already contains the 'contact' part of the url (from example 2 ). So it is likely to have been generated elsewhere by the core, which I shouldn't mess with.

Is there a setting I can change so Joomla! creates the urls I want to use?
Can I otherwise somehow generate the appropriate urls in the 'mod_articles_category/default.php'?

Thanks for your time.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30915
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Articles - Category in a module position creates multiple urls for one article

Post by Per Yngve Berg » Wed Dec 26, 2018 5:13 pm

Mod. Note: Relocated the topic to the SEO Forum.

It all depends of your menu items. 'contact' most likely a menu item.

Morissius
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Tue Oct 31, 2017 7:41 pm

Re: Articles - Category in a module position creates multiple urls for one article

Post by Morissius » Wed Dec 26, 2018 5:37 pm

Per Yngve Berg wrote:
Wed Dec 26, 2018 5:13 pm
Mod. Note: Relocated the topic to the SEO Forum.

It all depends of your menu items. 'contact' most likely a menu item.
I think you are right that the unwanted part of an url comes from the main navigation menu. Is there any way to turn that behavior off / create an override?

PS: The SEO part was just an introduction. The question may be a bit more technical in nature than the average SEO question.

Morissius
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Tue Oct 31, 2017 7:41 pm

Re: Articles - Category in a module position creates multiple urls for one article

Post by Morissius » Wed Dec 26, 2018 6:19 pm

I think I found a solution that may work. Instead of loading the normal $item->link I overrode the 'mod_articles_category/default.php' with some custom php.

Code: Select all

mod_articles_category/default.php

I replaced <?php $item->link; ?> with:
<?php echo str_replace(":", "-", $item->catslug).'/'.str_replace(":", "-", $item->slug); // override of $item->link ?>
It seems to be working so far. Note that my solution will cause trouble when an user uses colons in their slugs. You could probably simplify the code and avoid the colon scenario completely if you are using the new router.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30915
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Articles - Category in a module position creates multiple urls for one article

Post by Per Yngve Berg » Wed Dec 26, 2018 6:51 pm

If the article is how without a menu item, you have no control over how it's displayed.
The normal is to use a menu item.

Do you use the legacy or modern routing? (set in the options of article manager)
With modern, there will be no id numbers in the url.

Morissius
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Tue Oct 31, 2017 7:41 pm

Re: Articles - Category in a module position creates multiple urls for one article

Post by Morissius » Wed Dec 26, 2018 8:31 pm

Per Yngve Berg wrote:
Wed Dec 26, 2018 6:51 pm
If the article is how without a menu item, you have no control over how it's displayed.
The normal is to use a menu item.

Do you use the legacy or modern routing? (set in the options of article manager)
With modern, there will be no id numbers in the url.
Thanks for your reply. As you can read in the reply above, I think I figured it out ;).

I will leave the question marked as unresolved for a little while longer, since people may still have good feedback on it.

I am stuck with the old routing for now ( This project is using a cheap hosting company which delayed updating to php7 for over a year now, so I can't update Joomla properly. I suppose I should put some pressure on the site owners to switch hosting ).

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30915
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Articles - Category in a module position creates multiple urls for one article

Post by Per Yngve Berg » Thu Dec 27, 2018 8:25 am

There are SEF extensions where you can set the URL as you which.


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”