2013-08-12 102 views
0

我尝试重定向我所有的404错误在我的网站下面的那些文档:处理404错误的Joomla 2.5

http://docs.joomla.org/Creating_a_Custom_404_Error_Page

所以我编辑我的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; 
?> 

但是,当我点击一个链接,应该重定向到一个404错误页面 - 现在应该重定向到我的主页,它转到下面的链接,而不是:

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

我怎么可能解决这一问题?

+0

重定向404到您的主页是一个坏主意。如果页面没有了,你需要提供404,否则Google会给你提供问题。您应该使用搜索功能和/或其他相关链接自定义404错误页面。请参阅下面的原始问题。 –

回答

0

Joomla在构建页面时需要一个itemID。我的猜测是你的默认页面是项目编号359.Joomla将它附加到URL很有可能是因为你没有打开重写的SEF URL。

你需要(更普遍)
+0

好猜,谢谢 –

0

正确的代码是:

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

一些建议之下,但我只是想重定向到主页不是一篇文章:

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