MyBB Tutorials

Custom 404 Page

Submitted by Mr_Joker, , Thread ID: 4835

Thread Closed
15-06-2015, 09:10 AM
#1
First of all, you're gonna want to add this code to the last line on your .htaccess file.

Code:
ErrorDocument 404 /filenotfound.php

Now, you want to create a new page, called 'filenotfound.php' and add this code to it.
Code:
<?php     define('IN_MYBB', 1);
    require_once("global.php");

    add_breadcrumb("404 Error", $_SERVER['PHP_SELF']);

    eval("\$page = \"".$templates->get("404")."\";");

    output_page($page);
?>

Now, upload the filenotfound.php file to your main website's directory.

Then, create a new template on your main theme with the name 404 and add this to it:
Code:
<html>
<head>
<title>Your title</title>
{$headerinclude}
</head>
<body>
{$header}
Your 404 Page Content
{$footer}
</body>
</html>

Edit where it says Your 404 Page Content to whatever suits your needs.

Not my content don't come to me if shit doesn't work but it should Smile

RE: Custom 404 Page

#2
or you can just create custom error pages in the cpanel.

RE: Custom 404 Page

#3
I'll test on my administrator panel thanks Smile

RE: Custom 404 Page

#4
Thanks, i needed this :p

RE: Custom 404 Page

#5
I was searching for this for a while.. I'll test this Smile

RE: Custom 404 Page

#6
Will definitely put this to use thanks in advance haha. Sounds good.

RE: Custom 404 Page

#7
this is helpful been looking for something like this thanks for sharing

RE: Custom 404 Page

#8
Has anyone tested this compared to the cPanel fix, which is better?
Love to CODE, DESIGN, ILLUSTRATE & CREATE? The 1st COMMUNITY-SOURCED CREATIVE PROJECT COLLABORATIVE is For YOU!
[ TWT @Code_Collective ]

RE: Custom 404 Page

This post was last modified: 13-08-2018, 08:46 PM by Bassdrop
#9
13-08-2018, 08:25 PM
webelious Wrote:
Has anyone tested this compared to the cPanel fix, which is better?

Cpanel just edits the .htaccess file I'm pretty sure.

You can use any html/php file for the error page(s)... you can set all the error types that way, for example:

Quote:ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404/404.html
ErrorDocument 500 /500.html


List oferror codes:

Client Error:
400 - Bad Request
401 - Unauthorized
402 - Payment Required
403 - Forbidden
404 - Not Found
405 - Method Not Allowed
406 - Not Acceptable
407 - Proxy Authentication Required
408 - Request Timeout
409 - Conflict
410 - Gone
411 - Length Required
412 - Precondition Failed
413 - Request Entity Too Large
414 - Request-URI Too Long
415 - Unsupported Media Type
416 - Requested Range Not Satisfiable
417 - Expectation Failed

Server Error:
500 - Internal Server Error
501 - Not Implemented
502 - Bad Gateway
503 - Service Unavailable
504 - Gateway Timeout
505 - HTTP Version Not Supported


You can also put html directly in the .htaccess fileusing a quotation mark before the html (you don't need one at the end, and you can use quotes in the html itself....

For example:

Quote:ErrorDocument 404 "<span style="font-size:1.2em;"><b>404:</b>Shit, we couldn't find that page!</span><br><br>Click <a href="https://your.site/">here</a> to go to the main page or <a href="mailto:[email protected]">email us</a> for help.
ErrorDocument 403 "<center>You're forbidden from accessing this content.<br><span style="font-size:10px"><a href="http://link.to/site">(Return to main page.)</a></center>

Better just to use a separate file though.

Life is like a box of chocolates, it doesn't last as long for fat people.

Users browsing this thread: 1 Guest(s)