Remove the category ID from the url

Before you ask see the Phoca Gallery User Manual
Maximus
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 28 May 2015, 13:17

Remove the category ID from the url

Post by Maximus » 28 May 2015, 13:52

Dear developer! First of all thank you for this lovely gallery.

Very hope for your help.

Tell me, please, how can I remove the category ID from the url.

It is very necessary for SEO, because, for example, category:

/gallery/category/1-plants

also available at:

/gallery/category/1-plant
/gallery/category/1-plan
/gallery/category/1-pla

and so on, because she has a numeric identificator. I need to such pages as:

/gallery/category/1-plant
/gallery/category/1-plan
/gallery/category/1-pla

would have given a 404 error, and I think it will turn out, if I can remove the category ID: /gallery/category/plants

I think I need to edit the file \www\components\com_phocagallery\router.php, but my knowledge is not enough.

I think the solution would be very useful for many other users.

Many thanks in advance.

P.S. Please, sorry for my bad English.


User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 39060
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Remove the category ID from the url

Post by Jan » 31 May 2015, 22:53

Hi, I think, this is a Joomla! forum question as the SEF (routes, URLs, ...) are made by Joomla! router methods (JRouter).

Anyway the numbers in urls are good for search outcomes, when the alias is changed, the link is still accessible thank to the number.

Jan
If you find Phoca extensions useful, please support the project

Maximus
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 28 May 2015, 13:17

Re: Remove the category ID from the url

Post by Maximus » 01 Jun 2015, 22:16

Hello, Jan!

Thanks for your answer!

Yes, in that sense, I agree with You.

But I'd rather get rid of the numbers in the url, and in the event of a change of alias would prescribe redirect in htaccess or by using the appropriate plugin.

I assure You that otherwise, over time, in the Google search will be a large number of duplicates, that eventually will lead to pessimization of the site.

I managed to get rid of the numbers in the url in the categories and articles in Joomla using instructions that I found on the Internet. Just a small edit two lines in the rooter.php file and the problem is solved.

But, unfortunately, it didn't work on gallery categories, as it has its own router...

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 39060
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Remove the category ID from the url

Post by Jan » 03 Jun 2015, 14:54

Hi, yes, such you need to customize in the router - somehow detect the ID and parse it somehow with the alias. I didn't do such customization yet, but I think it can work this way:

- instead of IDs you will use only aliases
- when alias is comming - you need to detect it in the database and change to ID - load the items from database by the ID then.

:idea:

Jan
If you find Phoca extensions useful, please support the project

Maximus
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 28 May 2015, 13:17

Re: Remove the category ID from the url

Post by Maximus » 03 Jun 2015, 19:33

Hi Jan!

Thank You for the reply! Unfortunately, I can't do such adjustments.

If You don't mind, I'll write here changes that remove the ID from categories and news in Joomla 2.5 - Joomla 3.x.

Maybe someone wants to do such and in the Phoca Gallery, and it proves useful in solving the problem.
I would be very grateful if someone will succeed and he will share the solution in this topic.

Editing file: site.com/components/com_content/router.php

1. Line (twice):

Code: Select all

$advanced = $params->get('sef_advanced_link', 0);
Replace with (twice):

Code: Select all

$advanced = $params->get('sef_advanced_link', 1);
2. Find this pice of code:

Code: Select all

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

Code: Select all

/*if (strpos($segments[0], ':') === false)
{
$vars['view'] = 'article';
$vars['id'] = (int) $segments[0];
return $vars;
}*/
That's all.
In any case, thank You very much.

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 39060
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Remove the category ID from the url

Post by Jan » 08 Jun 2015, 11:10

Hi, thank you for the guide.

Jan
If you find Phoca extensions useful, please support the project

bart198x
Phoca Newbie
Phoca Newbie
Posts: 7
Joined: 04 Jun 2012, 21:40

Re: Remove the category ID from the url

Post by bart198x » 12 Feb 2017, 11:31

It's quite old, but I see, nothing changes to the router displaying from few years (since I stop using phoca in 2014 :) ).
I try to read router.php and actualy I was wondering why function

Code: Select all

function PhocaGalleryBuildRoute(&$query)
return $segments , when it is calculated once again in

Code: Select all

function PhocaGalleryParseRoute($segments)
. Doesn't it make doubled $segments or something?
So I just commented

Code: Select all

return $segments;
at the and of

Code: Select all

function PhocaGalleryBuildRoute(&$query)
and I noticed that link in browser changes from
/galeria/jesień-zima-monika/category/2-monika
to
/galeria/jesień-zima-monika
.
I don't know for sure is that correct, but it did the trick. (of course both /galeria and /galeria/jesień-zima-monika are menu items)
Best regards.


it's not so simple, was working until I added more categories :) . So back to the beginning...

User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 39060
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Remove the category ID from the url

Post by Jan » 15 Feb 2017, 10:50

Hi, there were a lot of changes in router (mostly regarding more menu links, etc.)

There is new router planned in Joomla! so first we need to wait for Joomla! new feature and then such can be implemented (if possible)

But try to seem some SEO guides, displaying the number in URL has mostly more positive implicaciones than negative (great for stablie and long term URLs. In case of different changes, always the same content will be displayed as it is based on number).

Jan
If you find Phoca extensions useful, please support the project

jacoline
Phoca Newbie
Phoca Newbie
Posts: 3
Joined: 21 Jan 2012, 11:55

Re: Remove the category ID from the url

Post by jacoline » 13 Aug 2017, 14:19

Any plans about hidding /category/catid- in browser url?
Joomla today has the ability (by htaccess) to remove the category/id but it does not affect the gallery. Or perhabs Im just unknown?

christine
Phoca Hero
Phoca Hero
Posts: 1060
Joined: 28 Nov 2010, 17:20

Re: Remove the category ID from the url

Post by christine » 13 Aug 2017, 17:09

Hi,
Jan wrote:
15 Feb 2017, 10:50
There is new router planned in Joomla! so first we need to wait for Joomla! new feature and then such can be implemented (if possible)
History behind: https://developer.joomla.org/news/674-s ... 3-7-0.html
jacoline wrote:Any plans about hidding /category/catid- in browser url?
Plan for Joomla 3.8 > https://www.smartaddons.com/blog/plan-f ... 38-release. Includes also link: discussion new router.

Kind regards, Christine

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests