Custom page for when wordpress is down

josh72

New Member
Messages
42
Reaction score
0
Points
0
Hey, anyone out there who uses wordpress for their site
Due to the updates going on here at x10 my wordpress blog is down
it comes up with a "Error establishing a database connection" page
I'm just wondering if i could either make a new page or modify that page, so that if i get visitors whenever the blog is down, ill be able to give them some custom info and maybe redirect them
Any help appreciated :)
 

Zubair

Community Leader
Community Support
Messages
8,766
Reaction score
305
Points
83
Create a index.html file in wordpress root folder, design a simple page for news about the website.
Now you will get this custom page instead of wordpress when you will open your website. If you want to put wordpress back online, just remove or rename index.html file.
 

josh72

New Member
Messages
42
Reaction score
0
Points
0
thanks for the info, but im looking for something more automatic
i'd like that page to come up only when the wordpress blog is down
 

lemon-tree

x10 Minion
Community Support
Messages
1,420
Reaction score
46
Points
48
The simplest way would be to create a page, similar to what Zubair suggested but not named index.html but instead named something like offline.html. You would then need to look inside your Wordpress install and find the PHP code that checks the database connection and alter it so that when an error occurs it will redirect to the offline.html page using the header() function. This is how I do it on my site, although with a few differences as the error page is loaded in rather than redirected. Be aware that you will have to redo all the changes every time you updates Wordpress.
Otherwise, there is probably a plugin around that does what you want.
 
Last edited:

dlukin

New Member
Messages
427
Reaction score
25
Points
0
From wp-includes/functions.php in WordPress
* Load custom DB error or display WordPress DB error.
*
* If a file exists in the wp-content directory named db-error.php, then it will
* be loaded instead of displaying the WordPress DB error. If it is not found,
* then the WordPress DB error will be displayed instead.
*
* The WordPress DB error sets the HTTP status header to 500 to try to prevent
* search engines from caching the message. Custom DB messages should do the
* same.

ie, create a page db-error.php and put it in wp-content directory. It can do anything that a normal php page would do. But remember not to call MySQL :wink:
 

josh72

New Member
Messages
42
Reaction score
0
Points
0
Thanks people i finally got it working
I ended up modifying some code in the functions.php file
I found the section of the file which had the code which displayed the 'Error establishing a database connection' message when a person viewed the page
I then changed that to my own personal message with a hyperlink included to redirect visitors to a backup html page
 

fretwizz

Member
Messages
106
Reaction score
3
Points
18
Could you detail what you did a bit better (show the pertinent code, maybe)?

Thanks
 

josh72

New Member
Messages
42
Reaction score
0
Points
0
I went into the functions.php file with Notepad++
Then i searched for: 'Error establishing a database connection'
Theres only one instance in the file where that text is
I just changed that line to display my own custom message with a link to a plain html page

</head>
<body>
<h1>Error establishing a database connection</h1> <------------------Change this to your message
</body>
</html>
<?php
die();
 
Top