目录
[隐藏]

Joomla 404

A创建一个未分类文章:

创建一篇不属于任何分类的文章命名为:“404”。然后编辑内容,比如:“对不起,你要访问的页面已被删除”之类的文字,或者指向首页的链接。Joomla 404

404_Uncategorized

B创建Joomla 404页面链接:

创建一个新的菜单项,链接到这个“404”文章,将这个菜单项设为“未发布”。

404_link

C复制error.php模板:

将 your_site_root/templates/system下的error.php到你的模板目录: your_site_root/templates/your_templates下。

D修改error.php文件重定向404错误页面到404文章:

a对于Joomla!1.5系统:

Compat_icon_1_5 打开error.php文件,找到第13行的:


1
defined( '_JEXEC' ) or die( 'Restricted access' );

 

在后面添加代码:


1
2
3
4
if (($this->error->code) == '404') {
header('Location: index.php?option=com_content&view=article&id=134');
exit;
}

将Location:后面的index.php?option..换为之前创建的404菜单链接地址。Joomla 404

b对于Joomla!1.6/1.7/2.5系统:Joomla 404

Compat_icon_1_6Compat_icon_1_7Compat_icon_2_5 打开error.php文件,找到第13行的:


1
8.defined('_JEXEC') or die;

 

在后面添加代码:


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

将Location:后面的index.php?option..换为之前创建的404菜单链接地址。c如果你开启了SEF(搜索引擎友好网址):

将Location:后面的index.php?option..换为之前创建的404菜单链接地址重写规则,比如菜单项别名:


1
2
3
4
if (($this->error->getCode()) == '404') {
header('Location: 404.html');
exit;
}

E附加步骤(可选):

打开根目录下的 your_site_root/robots.txt文件,添加代码:


1
Disallow: /index.php?option=com_content&view=article&id=134

同样,如果开启了SEF(搜索引擎友好网址),则改为:


1
Disallow: /404

This tutorial will show you how to create a custom 404 error page for use in your Joomla Webssite.

Four Steps to Creating a Custom 404 Error Page

  1. Create an Uncategorized '404' Article
    Create an 'uncategorized' article in Joomla! to serve as your 404 Page. Include some text such as Sorry, we could not find the page you were looking for... and if necessary, also any useful navigational links. For example, you may wish to add a link back to your site's home page.
  2. Create and copy a link to that new 404 Article.
    Create a menu item which links to the new 404 Article and 'apply' your changes. Then copy the URL information (index.php?optio...), set the menu item as 'unpublished' and close out of the menu editing page. You may want to paste the copied URL into Notepad or somewhere accessible for the time-being.
  3. Copy error.php to your Template's Directory
    In your Joomla! installation copy the file error.php from the templates/system directory, to your Template directory. For example, if I was using a template named 'Cleancloud' I would copy the error.php file to the templates/cleancloud directory.
  4. Modify error.php to Redirect 404 Errors to your 404 Article
    Edit the error.php file as follows, adding the code below immediately under the 'restricted access' line:

1
2
3
4
if (($this->error->code) == '404') {
header('Location: /index.php?option=com_content&view=article&id=75');
exit;
}

If you are using Joomla 1.6, 1.7 and 2.5, use this detection code instead:


1
if (($this->error->getCode()) == '404') {

Replace the location information (index.php?option..) with the URL from the menu item you created.

Additional Steps Toward a Better Custom 404 Error Page

  • Add the following line to the robots.txt file located in the root directory of your Joomla! installation.
    1
    Disallow: /index.php?option=com_content&view=article&id=75
  • Replacing the (index.php?option..) location with your 404 Article URL.

via:

http://zh95330.zhenghao.org/joomla/joomla-fix/item/112-creating-a-custom-404-error-page

http://docs.joomla.org/Creating_a_Custom_404_Error_Page

Joomla 404