403 and 404 Error pages

Submitted by Anonymous on Sat, 10/13/2012 - 01:05
Written by
mrGTB

I've spotted there's some code listed in a php forum file mentioning error pages like 403 and 404, so thought forum dealt with them. But if you get 403 or 404 it just serves up the web server default error pages, blank white pages. Is there an easy way to edit the code in the php file to instead re-direct back to homepage for both. Because you don't want to be showing default server error pages really that don't link back to your board.

In common.php file is this:

define('HEADER_403', $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
/**
* 404 header
*/
define('HEADER_404', $_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
/**

I do know if you delete a thread and it's still listed in Google, that will show a forum error page in that instance if clicked via google search.

I've solved it.

You can add this to htaccess file extra.


ErrorDocument 404 http://example.com/
ErrorDocument 403 http://example.com/

For others as well, you can remove WWW for better SEO using htaccess file by adding this (remember to remove WWW from admin CP forum homepage setting also).


RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Here is my htaccess file in full to see where I placed it:


# Copyright (C) 2003-2012 UseBB Team
# $Id$

Options -Indexes
DirectoryIndex index.php index.html

ErrorDocument 404 http://example.com/
ErrorDocument 403 http://example.com/

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteRule ^(index|panel|faq|search|active|online|members|rss|stats)\.html?[\.,;\-]?$ $1.php
RewriteRule ^index-([0-9]+)\.html?[\.,;\-]?$ index.php?cat=$1
RewriteRule ^panel-(login|logout|register|sendpwd|editprofile|editoptions|editpwd|subscriptions)\.html?[\.,;\-]?$ panel.php?act=$1
RewriteRule ^panel-al(0|1)\.html?[\.,;\-]?$ panel.php?al=$1
# No longer used, but kept for compatibility
RewriteRule ^panel-activate-([0-9]+)-([0-9a-zA-Z]+)\.html?[\.,;\-]?$ panel.php?act=activate&id=$1&key=$2
RewriteRule ^panel-markallasread\.html?[\.,;\-]?$ panel.php?do=markallasread
RewriteRule ^(forum|topic|profile|mail)-([0-9]+)\.html?[\.,;\-]?$ $1.php?id=$2
RewriteRule ^(forum|topic)-([0-9]+)-([0-9]+)\.html?[\.,;\-]?$ $1.php?id=$2&page=$3
RewriteRule ^topic-([0-9]+)-((un)?subscribe)\.html?[\.,;\-]?$ topic.php?id=$1&act=$2
RewriteRule ^topic-([0-9]+)-getnewpost\.html?[\.,;\-]?$ topic.php?id=$1&act=getnewpost
RewriteRule ^topic-post([0-9]+)\.html?[\.,;\-]?$ topic.php?post=$1
RewriteRule ^post-(forum|topic)([0-9]+)\.html?[\.,;\-]?$ post.php?$1=$2
RewriteRule ^post-topic([0-9]+)-quotepost([0-9]+)\.html?[\.,;\-]?$ post.php?topic=$1&quotepost=$2
RewriteRule ^edit-post([0-9]+)\.html?[\.,;\-]?$ edit.php?post=$1
RewriteRule ^edit-post([0-9]+)-delete\.html?[\.,;\-]?$ edit.php?post=$1&act=delete
RewriteRule ^edit-topic([0-9]+)-(delete|trash|move|lock|sticky|unlock|unsticky)\.html?[\.,;\-]?$ edit.php?topic=$1&act=$2
RewriteRule ^online-(all|members|staff|guests)\.html?[\.,;\-]?$ online.php?show=$1
RewriteRule ^online-(all|members|staff|guests)-([0-9]+)\.html?[\.,;\-]?$ online.php?show=$1&page=$2
RewriteRule ^members-staff\.html?[\.,;\-]?$ members.php?act=staff
RewriteRule ^faq-([0-9a-zA-Z]{5,})\.html?[\.,;\-]?$ faq.php?q=$1
RewriteRule ^search-results\.html?[\.,;\-]?$ search.php?act=results
RewriteRule ^search-results-([0-9]+)\.html?[\.,;\-]?$ search.php?act=results&page=$1
RewriteRule ^rss\.xml[\.,;\-]?$ rss.php
RewriteRule ^rss-(forum|topic)([0-9]+)\.xml?[\.,;\-]?$ rss.php?$1=$2
RewriteRule ^mail-admin\.html?[\.,;\-]?$ mail.php?act=admin
</IfModule>

mrGTB

I've spotted there's some code listed in a php forum file mentioning error pages like 403 and 404, so thought forum dealt with them. But if you get 403 or 404 it just serves up the web server default error pages, blank white pages. Is there an easy way to edit the code in the php file to instead re-direct back to homepage for both. Because you don't want to be showing default server error pages really that don't link back to your board.

In common.php file is this:

define('HEADER_403', $_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
/**
* 404 header
*/
define('HEADER_404', $_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
/**

I do know if you delete a thread and it's still listed in Google, that will show a forum error page in that instance if clicked via google search.

These are HTTP headers for errors inside UseBB, they are not used anywhere outside the forum.