Actions

Difference between revisions of "Creating a Custom 404 Error Page"

From Joomla! Documentation

m (removing category management)
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
This tutorial will show you how to create a custom 404 Error Page for use in your Joomla 1.5 Web Site.
+
This tutorial will show you how to create a custom 404 error page for use in your Joomla Webssite.
 
+
This page summarizes popular techniques for adding Joomla! 404 Error Pages, as discussed by Amy Stephens and others in the Joomla! Forum Post [http://forum.joomla.org/viewtopic.php?f=199&t=251089 Custom 404 Inside the Content Area]
+
 
+
  
 
== Four Steps to Creating a Custom 404 Error Page ==
 
== Four Steps to Creating a Custom 404 Error Page ==
 
+
# '''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.
 
+
# '''Create and copy a link to that new 404 Article.'''
'''1.  Create an Uncategorized '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.
 
+
# '''Copy error.php to your Template's Directory'''
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.
+
#: 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.
 
+
# '''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:
'''2.  Create and copy a link to that new 404 Article.'''
+
<source lang="php">
 
+
if (($this->error->code) == '404') {
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.
+
header('Location: /index.php?option=com_content&view=article&id=75');
 
+
 
+
'''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:
+
 
+
<pre> if (($this->error->code) == '404') {
+
header('Location: index.php?option=com_content&view=article&id=75');
+
 
exit;
 
exit;
} </pre>
+
}
 
+
</source>
 +
If you are using Joomla 1.6, 1.7 and 2.5, use this detection code instead:
 +
<source lang="php">
 +
if (($this->error->getCode()) == '404') {
 +
</source>
 
Replace the location information (index.php?option..) with the URL from the menu item you created.
 
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.
 +
*: <code>Disallow: /index.php?option=com_content&view=article&id=75</code>
 +
* Replacing the (index.php?option..) location with your 404 Article URL.
 +
* Follow the Best-Practices described here:  http://www.alistapart.com/articles/perfect404/
 +
* Be creative, add a [http://www.geekhaiku.com/tag/404/ 404 Haiku] or maybe an [http://www.smashingmagazine.com/2007/08/17/404-error-pages-reloaded Interesting Photo]
  
 
+
== More Custom Error Page Information ==
== Additional Steps toward a Better Custom 404 Error Page ==
+
* [[Custom_error_pages|Custom Error Pages]]
 
+
* [[System_error_pages|System Error Pages]]
 
+
* Add the following line to the robots.txt file located in the root directory of your Joomla! installation.
+
 
+
  <pre>Disallow: /index.php?option=com_content&view=article&id=75</pre>
+
 
+
Replacing the (index.php?option..) location with your 404 Article URL.
+
 
+
*  Follow the Best-Practices described here:  http://www.alistapart.com/articles/perfect404/
+
 
+
*  Be creative, add a [http://www.geekhaiku.com/tag/404/ 404 Haiku] or maybe an [http://www.smashingmagazine.com/2007/08/17/404-error-pages-reloaded Interesting Photo]
+
 
+
 
+
 
+
 
+
'''More Custom Error Page Information:'''
+
 
+
* [http://docs.joomla.org/Custom_error_pages Joomla! Documentation: Custom Error Pages]
+
* [http://docs.joomla.org/System_error_pages Joomla! Documentation: System Error Pages]
+
 
* [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html HTTP/1.1 Status Code Definitions]
 
* [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html HTTP/1.1 Status Code Definitions]
 
* [http://www.google.com/support/webmasters/bin/answer.py?answer=83040&topic=8474 Google Webmaster - Analyzing Crawl Errors]
 
* [http://www.google.com/support/webmasters/bin/answer.py?answer=83040&topic=8474 Google Webmaster - Analyzing Crawl Errors]
 
 
  
  
 
[[Category:Tutorials]]
 
[[Category:Tutorials]]

Revision as of 23:49, 7 August 2012

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:
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:

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.
    Disallow: /index.php?option=com_content&view=article&id=75
  • Replacing the (index.php?option..) location with your 404 Article URL.
  • Follow the Best-Practices described here: http://www.alistapart.com/articles/perfect404/
  • Be creative, add a 404 Haiku or maybe an Interesting Photo

More Custom Error Page Information