APACHE custom 404 error page setup method

  • 2020-05-27 08:03:50
  • OfStack

Method 1:

Set the directory to open in httpd.conf.

AllowOverride All

Then put 1.htaccess (.htaccess) in the directory and add:

errorDocument 404 /404.php

1. Rewrite this to suit you. However, sometimes when you browse with IE, you will find that it does not jump at all. The key point is html. If the value of 404.html is less than 512 bytes, IE will think that the error page is not "friendly" and will ignore it!
2. Must be placed in the root directory of the website (www/), the placement (www/phpcms/) is invalid!

If you have multiple items in the web directory, you must have.htaccess under each item, and you just need to fill in the corresponding 404 page. Note that the 404 page is in the web root

Method 2:

Modify httpd.conf, find:

#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html

This part of httpd.conf,#ErrorDocument 404 / missing.html, displays the error page information. Remove the previous # and change it to:

ErrorDocument 404 /404.php

1. Do not redirect a 404 error to the home page, which may cause it to disappear from search engines. If the content of a 404 page is less than 512b, IE will consider the 404 page unfriendly, and the 404 error page will not be returned successfully under IE.
2. Never use absolute URL. For example: http: / / xiazai. ofstack. com / 404. PHP. Normally a 404 status code is returned, while an URL form returns a 200 status code.

(2) customize url

When Posting goods or information in the background, add a field to save the url address.

(3) hyperlink directly links to the custom url
(4) set the 404 page because the custom hyperlink does not exist, the system will automatically jump to the 404.php page, and then use the php code to obtain the access path of the address bar

This method sets the default 404 page, and if there are multiple projects in the directory, you can configure a 404 page for each project individually, refer to method 1.

apache server starts rewrite mode summary to resolve 404 error

The 404 error was resolved by comparing the local wampserver configuration file with the apache configuration file on the server

1: enter the conf directory of the apache directory
2: open httpd.conf
3: find #LoadModule rewrite_module modules/ mod_es1064en.so and remove the # in front
4: find all AllowOverride configuration items and change all None to All
5: create a new.htaccess file (what? This file will not be added? Create a new txt and save it as.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]

6: restart apache

Related articles: