Skip to main content

Change view question url

24 Views
0 Replies
2 min read

Hello,

on Joomla 4.1 and Community Answers 5.3.5 i've set the following (menu item type - url/alias):

-> /main_alias.html

-> /main_alias/view.html

-> /main_alias/resolved.html

-> /main_alias/resolved/{catid_as_alias}.html

My need is to replicate url structure in manual migration from J1.5 (hard and long work, but super necessary for my website with 5M UU/month with strong rankings in SERPs).

What i need to accomplish is to have every single question accessible in the following url structure:

/main_alias/view/{question_id}-{question_alias}.html

I've edited /components/com_communityanswers/helpers/route.php and added $catid = 0; in order to have

public static function getQuestionRoute ($id, $catid = 0, $language = 0, $start = 0)
{
$categories = JCategories::getInstance('CommunityAnswers');
$needles = array('question' => array((int) $id));

$link = 'index.php?option=com_communityanswers&view=question&id=' . $id;

$catid = 0;

if ((int) $catid > 1)
{
$category = $categories->get((int) $catid);
if ($category)
{
$needles = array_reverse($category->getPath());
$needles = $needles;
$link .= '&catid=' . $catid;
}
}

if ($language && $language != "*" && JLanguageMultilang::isEnabled())
{
self::buildLanguageLookup();

if (isset(self::$lang_lookup))
{
$link .= '&lang=' . self::$lang_lookup;
$needles = $language;
}
}

if($start > 0)
{
$link .= '&start=' . $start;
}

// add root category to needles in case there is no corresponding category menu item found.
$root = $categories->get('root');
$needles = $root->id;
$needles = array(0);

if ($item = self::_findItem($needles))
{
$link .= '&Itemid=' . $item;
}

return $link;
}

Now in main page and in category page i've links with urls in the desired structure:

/main_alias/view/{question_id}-{question_alias}.html

but all these links lead to 404 pages, and single questions are still accessible via urls with structure

/main_alias/resolved/{catid_as_alias}/{question_id}-{question_alias}.html

How can i:

- make url structure /main_alias/view/{question_id}-{question_alias}.html work?

- avoid url structure /main_alias/resolved/{catid_as_alias}/{question_id}-{question_alias}.html work?

Thank you in advance!

0 Replies

No Replies Yet

Topic Author

Topic Stats

Created Saturday, 30 April 2022 21:55
Last Updated Monday, 02 May 2022 12:52
Replies 0
Views 24
Likes 0

Share This Topic