{"id":34911,"date":"2015-03-18T10:30:33","date_gmt":"2015-03-18T17:30:33","guid":{"rendered":"http:\/\/www.bruceclay.com\/blog\/?p=34911"},"modified":"2023-01-31T13:02:05","modified_gmt":"2023-01-31T21:02:05","slug":"how-to-configure-a-404-error-page-apache","status":"publish","type":"post","link":"https:\/\/www.bruceclay.com\/blog\/how-to-configure-a-404-error-page-apache\/","title":{"rendered":"How to Configure a Custom 404 Error Page \u2014 Apache Server Edition"},"content":{"rendered":"
A 404 File Not Found page \u2014 also known as a 404 error page \u2014\u00a0is a web page that lets a user know when the page they are trying to access cannot be located.\u00a0A custom<\/em> 404 error page is a 404 error page that is crafted thoughtfully with user experience in mind. Custom 404 error pages are put into place to fend off confusion, explain the situation, and offer thoughtful next steps that keep the ball rolling.<\/p>\n To get a custom 404 error page up and running on your website, you\u2019ll need to do some communicating with your server.<\/p>\n How you go about getting a custom 404 error page setup on your server will vary greatly depending on your server type. This article addresses how to set up a custom 404 error page on an Apache server. \u00a0<\/strong><\/p>\n Getting a custom 404 error page up and running on the Apache Server is a five-part process:<\/p>\n In this post we cover parts 3,\u00a04 and 5\u00a0of this process; you should already have parts 1\u00a0and 2\u00a0done. If you haven\u2019t designed your custom 404 error page yet, read How to Design a 404 Error Page That Saves a Sale<\/a>\u00a0for strategic inspiration.<\/p>\n Your website is hosted on a server<\/em><\/a> that dishes out web pages when people navigate to URLs within your domain. There are several types of servers.<\/p>\n If you aren\u2019t using WordPress and you don\u2019t know what kind of server you are using, call your server provider (the people you pay to host your website every month \u2013 like BlueHost<\/a>, for instance), and ask them. While you have them on the line, make sure to also ask them if it is possible to set up a custom 404 error page; most server providers allow you to do this, but not all.<\/p>\n If your server provider tells you your website is hosted on the most widely used Web server \u2014\u00a0the Apache server \u2014\u00a0then read on!<\/strong><\/p>\n If you are reading this blog post, I am assuming that you don\u2019t have the luxury of asking an IT department to set your custom 404 error page up for you. If you do<\/em> have an IT\/systems department to refer to, by all means, ask for help! IT folks love servers and lines of code that talk to servers, and they effectively know how to handle both.<\/p>\n If you\u2019re going in on your own, it\u2019s smart to make sure you have your entire website backed up before you make any changes to code at the server level. The amendments we\u2019ll be making to add a custom 404 error page are minimal, but it\u2019s always better to be safe than sorry when it comes to tinkering with server-side code.<\/p>\n This blog post is written to help folks using the Apache server add a custom 404 error page to their website. Like most processes, there\u2019s inherently After identifying that you are using the Apache server, the first step is to locate your .htaccess file.<\/p>\n A .htaccess file is a file that communicates how and when your server should deliver specific information to your end user. In this case, specifically, when your server should deliver a fancy, custom-made 404 error page. Your .htaccess file should already be in the root directory of your website.<\/p>\n To access your .htaccess file:<\/p>\n If you see a .htaccess file, move on to step three.<\/strong><\/p>\n If you don\u2019t see a .htaccess file, make sure that your FTP is set to show hidden files (notice that period in front of the .htaccess file? That period means your .htaccess file it is a hidden file<\/em>.). To show hidden files using Cyberduck, go to the View dropdown, then choose Show Hidden Files. To show hidden files using Filezilla, go to the Server dropdown, then choose Force Showing Hidden Files.<\/p>\n If you force your FTP to show hidden files and you still don\u2019t see a .htaccess file, it means you don\u2019t have one and you will have to make one. In that case, move on to step two.<\/p>\n Fair warning: While any\u00a0novice can\u00a0create a .htaccess file (we\u2019re going to show you how right here!), if you have an IT department this is a really, really good time to bring them in the loop. If you don\u2019t have an IT department, now would be a great time to create that website backup if you haven\u2019t already!\u00a0 Your .htaccess file is going to communicate critical information to every page of your website, so it\u2019s smart to have a backup plan in case things get a little haywire.<\/p>\n To create an .htaccess file, use a text editor like Notepad++<\/a> on a PC, or TextEdit<\/a> on a Mac.\u00a0Name the file .htaccess \u2014 and don\u2019t forget the \u201c.\u201d It needs to be named .htaccess (periodhtaccess), not just htaccess. To keep your .htaccess file clean, make sure your text editor has word wrap disabled, and that it\u00a0is using UNIX-style line endings. Also, make sure there aren’t any file extensions added to your .htaccess file when you save it. You want to choose All Files<\/em> (not Text<\/em> or any other file type) from the Save As Type dropdown menu and save to the Desktop.<\/p>\n That\u2019s it! After you save you\u2019re done creating your .htaccess file. The file won\u2019t do anything<\/em> until you’ve uploaded it to the public_html folder of your server via FTP but, to streamline the process, we\u2019ll wait until after we amend the file (as outlined in step three) to upload it to the server.<\/p>\n Using\u00a0your text editor, add this one line of code to your .htaccess file, followed by a blank line:<\/p>\n There\u2019s four\u00a0parts to this line of code: [the phrase ErrorDocument] [the error number] [the absolute URL of the web page where custom 404 content lives] [the blank line that follows the line of code]. Make sure you carefully\u00a0include all four elements (No typos! No exclusions!) and make sure you replace the placeholder “custom-404.html” with the actual URL extension\u00a0where your custom 404 error page lives.<\/strong><\/p>\n The URL that you put in the ErrorDocument directive needs to be a:<\/p>\n 1. Relative URL — no http and no domain name.<\/p>\n 2. Static file — meaning Apache can serve it directly (no proxy, no application server, etc.); otherwise, Apache will assume the file is on another server and issue a redirect to the browser to go there.<\/p>\n It\u2019s this one line of code that tells your .htaccess file to deliver a custom 404 page when someone asks for a web page that cannot be located.<\/p>\n Make your .htaccess file alliiivvvveeee<\/em> (like Frankenstein) by using your FTP to upload your amended file to your server.<\/p>\n Once it\u2019s uploaded to the root directory of your server, it\u2019s live and your 404 error page should be working (assuming you\u2019ve made your 404 error URL live, as well).<\/p>\n The final step in every optimization process needs to be testing. We never set it and forget it in our industry. To test if everything is in working order If you see your custom 404 error page, everything is working! You have succeeded!<\/p>\n If you don\u2019t see your custom 404 error page, something is wrong. Try to isolate the problem with these troubleshooting tips:<\/p>\n If none of these troubleshooting tips uncover your problem\u2026 now might be a good time to seriously consider hiring that contract IT guy or gal.<\/p>\n Even if you are a UX minimalist\u00a0— no matter how big or small your company is —\u00a0you need to consider a properly configured 404 error page a technical SEO<\/a> essential.\u00a0You absolutely can do all the steps outlined in this post,\u00a0from locating your hidden .htaccess file or creating a\u00a0new one, to writing a line of code that works. Think of it like baking a cake: you have the recipe, now you just need to put all the ingredients together.<\/p>\n Just follow this five-step process:<\/p>\n 1. Get confirmation that you’re using the Apache server and\u00a0the thumbs up to proceed with a custom 404 from your server\u00a0host.<\/p>\n 2. Work with your web designer to\u00a0create a custom 404 error page<\/a>.<\/p>\n 3. Make your 404 error page live.<\/p>\n 4. Use your public_html folder and .htaccess file to tell your server to deliver the 404 error page anytime a request is made for a web page that doesn\u2019t exist.<\/p>\n 5. Test, test, test.<\/p>\n Have questions? Ask in the comments section below.<\/strong><\/p>\n <\/p>\n Getting a custom 404 error page up and running on the Apache Server is a five-part process. In this post we cover parts 3, 4 and 5 of this process; determining what type of server you’re using and amending your .htaccess file to tell your Apache server to deliver a custom 404 error page, and testing. If you’re using an Apache server — read on! <\/p>\n<\/a>
\n
How to Determine Your Server Type<\/h2>\n
<\/a>First, the easiest one: If you are using WordPress,\u00a0then you know you\u2019re using WordPress and you should read about WordPress 404 error page setup<\/a>; this Apache server article will not help you. Similarly, if you happen to be using Microsoft IIS, then you should read our How to Configure a Custom 404 Error Page in Microsoft IIS Server<\/a> post.<\/p>\n
Proceed with Caution!<\/h2>\n
How to Tell Your Server to Deliver the 404 Error Page<\/h2>\n
<\/a>more than one way to do this. The following five-step process is the most universal method<\/strong>, as it only requires FTP access to your server and a text editor, like Notepad++<\/a>\u00a0(on a PC) or TextEdit (on a Mac). (It’s worth mentioning here that Notepad [the\u00a0default text editor in Windows] and Notepad++ are not the same thing. If you’re using a PC, we recommend downloading the free Notepad++ text\u00a0editor<\/a>;\u00a0using\u00a0the standard release version of Notepad may cause errors if the server is running Linux.)<\/p>\n
Step 1: Locate or create your .htaccess file<\/h3>\n
\n
<\/a>
<\/a>
Step 2: Create your .htaccess file (if you don\u2019t already have one)<\/h3>\n
<\/a><\/p>\n
Step 3: Use a text editor to edit the .htaccess file<\/h3>\n
ErrorDocument 404 \/custom-404.html\r\n\r\n<\/strong><\/pre>\n
Step 4: Use FTP to upload your amended .htaccess file to your server<\/h3>\n
Step 5: Test it! Make sure your 404 error page is working<\/h3>\n
<\/a>with your .htaccess file and your new custom 404 error page, use your web browser to navigate to a page on your website that you know doesn\u2019t exist. For example: www.YourWebsite.com\/chelsea-is-awesome.<\/p>\n
\n
You Can Do This!<\/h2>\n
<\/a>