问题
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