[Tutorial] How to make a custom error 404 page

Get help with installation and running phpBB 3.0.x here. Please do not post bug reports, feature requests, or MOD-related questions here.
Ideas Centre
Forum rules
END OF SUPPORT: 1 January 2017 (announcement)
Locked
scarhextendedmags
Registered User
Posts: 68
Joined: Wed May 04, 2011 9:18 pm

[Tutorial] How to make a custom error 404 page

Post by scarhextendedmags »

**Apologies if this post is in the wrong place - please move it as appropriate**

Well, here it is. My first guide on how to do something useful on your phpBB forums :D
We are all familiar with the infamous Error 404, and when your users stumble across this page on your site due to a typo in a link, or an out-dated page that no longer exists, you are going to want a nice error 404 page so your users can easily get back to the rest of your site.
How to do this is relatively simple, and you need little knowledge overall - maybe a small amount of html so you can make your error page look nice :)

Here is what your current error 404 page will look like, without you interfering:
Like this:
Capture.PNG
Capture.PNG (220.09 KiB) Viewed 4345 times
Or like this:
Capture2.PNG
Capture2.PNG (43.01 KiB) Viewed 4345 times
When your users come across the default error 404 pages, they might just back out to Google and look for another site with the info they require. But if your Error 404 page can offer suggestions, or the reason why the page isn't there, the user is far more likely to stay on your page.

Alright, now my little intro is out of the way, it's time for the tutorial.

Step 1 -
Go to the root of your phpBB3 folder and download the file called .htaccess.
Open it with notepad (or any other similar program) and
Find:

Code: Select all

<Files "common.php">
Order Allow,Deny
Deny from All
</Files>
Add after:

Code: Select all

ErrorDocument 404 /404.php
Step 2 -
Now we must create our custom Error 404 page.
In a new notepad document, copy and paste the following code:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('Error 404 - Page Not Found');

$template->set_filenames(array(
    'body' => '404_body.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
Now save that document as "404.php" including the speech marks.

Step 3 -
Now we must create the body.html file that will display the content of your custom Error 404 page.
Create another new notepad document and save it as "404_body.html" including the speech marks.
Then copy and paste the following code:

Code: Select all

<!-- INCLUDE overall_header.html -->

<u><h2>Error 404 - Page Not Found</h2></u>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content"> <br><br>
            

             CONTENT GOES HERE


   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
In your 404_body.html file, you can customise the look of your Error 404 page by placing content where is says 'CONTENT GOES HERE' above.
Now, I'm not going to tell you what to put in there, as everybody's opinion is different, but here are some suggestions:
- A description to the user of what has happened
- Links to various places in your site
- A search bar or a link to the search page, so the user may find the information they are looking for quickly.
These are just some of the many things you could do.
On my Error 404 page, I added an image and some text below the image explaining the error and then placed a 'Back' button so the user could return to the previous page easily.

Step 4 -
Now you must upload all of the files you have edited to the correct location, and in the correct order; this is as follows:
1st, Upload 404.php to the root of your phpBB3 folder;
2nd, Upload 404_body.html to /styles/(YOUR STYLE)/template/;
3rd, Upload .htaccess to the root of your phpBB3 folder.

And that's it! Refresh your template via ACP -> Styles -> Templates -> Refresh and you can now view your custom Error 404 page by typing an incorrect page name in the URL. :P
Here is what mine looked like after I was finished:
Capture3.PNG
Capture3.PNG (269.37 KiB) Viewed 4345 times
Please feel free to leave a comment if this helped you and if I have done something wrong, or missed anything out, please correct me! :ugeek:

Credits:
Thanks to pentapenguin for their guide on how to make custom pages: http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/
Parkour Prologue - The ultimate resource for beginners Parkour and Free Running.
shifatul
Registered User
Posts: 18
Joined: Sun May 29, 2011 7:16 pm

Re: [Tutorial] How to make a custom error 404 page

Post by shifatul »

Thanks man
Helped me a lot
Great Tutorial - nice and easy
The most popular Android Forum - http://androids-forum.com
scarhextendedmags
Registered User
Posts: 68
Joined: Wed May 04, 2011 9:18 pm

Re: [Tutorial] How to make a custom error 404 page

Post by scarhextendedmags »

Thanks very much :D
Glad I could help 8-)
Parkour Prologue - The ultimate resource for beginners Parkour and Free Running.
User avatar
master412160
Registered User
Posts: 314
Joined: Sat May 22, 2010 5:45 pm
Name: Max Pen

Re: [Tutorial] How to make a custom error 404 page

Post by master412160 »

This tutorial helped me out alot. ;)
Regards, Matt.
User avatar
Lumpy Burgertushie
Registered User
Posts: 67926
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: [Tutorial] How to make a custom error 404 page

Post by Lumpy Burgertushie »

Ok, this aint' my first rodeo here, but I can not get this to work at all. I know it must be something simple.
It should work, it is very simple.
has anyone go this to work?

robert
Ok, I got it to work. there is something wrong with copying from the code box here and it was not the 4 extra spaces.

I used another custom page php file I have and just added the relevant parts and it works just fine.
I still don't know what the problem with the code in the code box above is.
robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

If nobody is in the forest, does a tree really fall?
scarhextendedmags
Registered User
Posts: 68
Joined: Wed May 04, 2011 9:18 pm

Re: [Tutorial] How to make a custom error 404 page

Post by scarhextendedmags »

Not sure why the code box does that :S Glad you got it to work though. Any other questions feel free to ask :D
Parkour Prologue - The ultimate resource for beginners Parkour and Free Running.
User avatar
Lumpy Burgertushie
Registered User
Posts: 67926
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: [Tutorial] How to make a custom error 404 page

Post by Lumpy Burgertushie »

well, once I got it to work then it messes up my login/logout system.

I could log in but as soon as it redirected back to the index page, I was logged out. If I tried to access the admin panel I get the error message about not having permissions.

as soon as I delete the 404.php file , those problems go away.

don't know why this is, it makes no sense to me, but I tried it on two different servers and 4 different boards.
It did not matter if the board was in the root or in a directory of the root.


robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

If nobody is in the forest, does a tree really fall?
scarhextendedmags
Registered User
Posts: 68
Joined: Wed May 04, 2011 9:18 pm

Re: [Tutorial] How to make a custom error 404 page

Post by scarhextendedmags »

Wow, sorry, that's beyond me :S I have never experienced these problems - Are you sure you followed all the instructions exactly?
Parkour Prologue - The ultimate resource for beginners Parkour and Free Running.
User avatar
Lumpy Burgertushie
Registered User
Posts: 67926
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: [Tutorial] How to make a custom error 404 page

Post by Lumpy Burgertushie »

scarhextendedmags wrote:Wow, sorry, that's beyond me :S I have never experienced these problems - Are you sure you followed all the instructions exactly?
yep, sure did. I have created custom error pages before and never had any problems.
I don't know what is wrong with either your tut or my execution of it but like I said, I tried different servers, different phpbbs etc. all with the same problem. messed up my login/logout process.

robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.3 Styles by PlanetStyles.net

If nobody is in the forest, does a tree really fall?
rAdic
Registered User
Posts: 426
Joined: Mon Apr 25, 2005 11:32 pm
Contact:

Re: [Tutorial] How to make a custom error 404 page

Post by rAdic »

Hi, this works fine for a general error like if you put a few characters at the end of the url like this:

http://www.australiaforums.com.au/izzzz

But if I write something like this:

http://www.australiaforums.com.au/izzzz/bbbb

it will not show the correct links and the stylesheet is not working . The links are following the same path i.e /izzzz/bbbb/

Anyone know how I can improve this?
The Australian Forums - Australia Discussion Forum - Discuss Australia topics or generally anything
Locked

Return to “[3.0.x] Support Forum”