Error 404 Httpd.conf
In submit Tutorials Questions Projects Meetups Main Site logo-horizontal DigitalOcean Community Menu Tutorials Questions Projects Meetups Main Site Sign Up Log In submit View All Results By: Justin Ellingwood Subscribe Subscribed Share Contents Contents We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more → 0 How To Configure Apache to Use Custom Error Pages on CentOS 7 Posted Jun 9, 2015 7.4k views Apache CentOS Introduction Apache is the most popular web server in the world. It is well-supported, feature-rich, and flexible. When designing your web pages, it is often helpful to customize every piece of content that your users will see. This includes error pages for when they request content that is not available. In this guide, we'll demonstrate how to configure Apache to use custom error pages on CentOS 7. Prerequisites To get started on with this guide, you will need a non-root user with sudo privileges. You can set up a user of this type by following along with our initial set up guide for CentOS 7. You will also need to have Apache installed on your system. Learn how to set this up by following the first step of this guide. Creating Your Custom Error Pages We will create a few custom error pages for demonstration purposes, but your custom pages will obviously be different. We will put our custom error pages in the /var/www/html directory where CentOS's Apache installation sets its default document root. We'll make a page for 404 errors called custom_404.html and one for general 500-level errors called custom_50x.html. You can use the following lines if you are just testing. Otherwise, put your own content in these locations:
- echo "
Error 404: Not found :-(
" | sudo tee /var/www/html/custom_404.html - echo "
I have no idea where that file is, sorry. Are you sure you typed in the correct URL?
" | sudo tee -a /var/www/html/custom_404.html - echo "
Oops! Something went wrong...
" | sudo tee /var/www/html/custom_50x.html - echo "
We seem to be having some technical difficulties. Hang tight.
" | sudo tee -a /var/www/html/custom_50x.html We now have two custom error pages that we can serve when client requests result in different errors. Configuring Apache to Use your Error Pages Now, we just need to tell Apache that it should be utilizing these pages whenever tgeneric error responses in the event of 4xx or 5xx HTTP status codes, these responses are rather stark, uninformative, and can be intimidating to site users. You may wish to provide custom error responses which are either friendlier, or in some language other than English, or perhaps which are styled more in line with your site layout. Customized error responses can be defined for any HTTP status https://www.digitalocean.com/community/tutorials/how-to-configure-apache-to-use-custom-error-pages-on-centos-7 code designated as an error condition - that is, any 4xx or 5xx status. Additionally, a set of values are provided, so that the error document can be customized further based on the values of these variables, using Server Side Includes. Or, you can have error conditions handled by a cgi program, or other dynamic handler https://httpd.apache.org/docs/trunk/custom-error.html (PHP, mod_perl, etc) which makes use of these variables. Configuration Available Variables Customizing Error Responses Multi Language Custom Error Documents See alsoComments Configuration Custom error documents are configured using the ErrorDocument directive, which may be used in global, virtualhost, or directory context. It may be used in .htaccess files if AllowOverride is set to FileInfo. ErrorDocument 500 "Sorry, our script crashed. Oh dear" ErrorDocument 500 /cgi-bin/crash-recover ErrorDocument 500 http://error.example.com/server_error.html ErrorDocument 404 /errors/not_found.html ErrorDocument 401 /subscription/how_to_subscribe.html The syntax of the ErrorDocument directive is: ErrorDocument <3-digit-code>
where the action will be treated as: A local URL to redirect to (if the action begins with a "/"). An external URL to redirect to (if the action is a valid URL). Text to be displayed (if none of the above). The text must be wrapped in quotes (") if it consists of more than one word. When redirecting to a local URL, additional environment variables are set so that the response can be further cu add your own 404 error page, error 404 page with apache, web server How to Create Your Own 404 Error Page Directions for Apache http://www.404-error-page.com/404-create-a-custom-404-error-page.shtml Users Directions for: Lycos/Tripod First off, it's not as hard as you think! These directions are for the popular Apache web browser but odds are pretty darn good that's what server you have anyway! if not, then a quick google of "adding a 404 error page" coupled with the name of your web server will probably do the trick! Step One: Modify the httpd.conf file error 404 The first step, and perhaps the most challenging, is to find your Web server configuration file - often called httpd.conf - and find the block of statements that define the location and behavior of your particular site. This file is commonly found at /etc/httpd/httpd.conf, /usr/local/www/conf/httpd.conf or a similar location: if you can't find it, ask your system administrator. On a typical server configuration, it might look error 404 httpd.conf like this:
Now that you've found this section, you need to add an ErrorDocument handler that specifies the exact numeric code and the name of the file to serve up (or CGI script to run) when that error is encountered. Here's how that might well look: ErrorDocument 404 /errordoc-404.shtml In this case, when error 404 is encountered - page or file not found - then the file errordoc-404.shtml will be served up (and notice that you can have server-side includes (SSI) in error documents if you'd like. One trick, though, is to remember that error pages can pop up anywhere in your site heirarchy, so make sure all your graphic references, links to other areas on the site, etc, are absolute references, that they start with '/' or, in extreme cases, 'http:'. Note: There's another way you can hook a custom 404 error page into your site too, using a .htaServerName www.intuitive.com ServerAdmin taylor@administration.com DocumentRoot /usr/local/www/intuitive.com ErrorLog logs/intuitive/error_log TransferLog logs/intuitive/access_log Your server might have dozens (or more) of these VirtualHost blocks in the configuration file: make sure you find the one for your exact domain name before you make any modifications.