Handling 404 error Joomla 2.5

妖精的绣舞 提交于 2020-01-07 06:19:06

问题


I try to redirect all my 404 error on my web site following those docs :

http://docs.joomla.org/Creating_a_Custom_404_Error_Page

So I edited my error.php :

<?php

defined('_JEXEC') or die;

if (($this->error->getCode()) == '404') {
header('Location: http://www.mywebsite.com');
exit;
}

        if { (!isset($this->error)) {
                $this->error = JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
                $this->debug = false;
        }

//get language and direction
$doc = JFactory::getDocument();
$this->language = $doc->language;
$this->direction = $doc->direction;
?>

But when I clic on a link that should redirect me to a 404 error page - which should now redirect to my home page, it goes to the following link instead :

http://www.mywebsite.com/index.php?Itemid=359

How may I solve that problem ?


回答1:


Joomla needs an itemID when building a page. My guess is that your default page is item ID 359. Joomla is appending that to the URL most likely because you do not have SEF URLs with rewrite turned on.




回答2:


Correct code that you need (and more general) is:

if (($this->error->getCode()) == '404') {
header('Location: /index.php');
exit;
}

Some suggested the below, but I just want to redirect to main page not to an article:

if (($this->error->getCode()) == '404') {
header('Location: /index.php?option=com_content&view=article&id=999');
exit;
}


来源:https://stackoverflow.com/questions/18181791/handling-404-error-joomla-2-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!