Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to do a 404 redirect with Apache, and I find several solutions:

  1. The .htaccess method. But I don't want to add a .htaccess if not necessary.

  2. virtual host method:

<VirtualHost *:80>
    ServerAlias *
    Redirect 404 /index.html
    ErrorDocument 404 /index.html

I would like to know what's the difference Redirect 404 and ErrorDocument 404?

share|improve this question

Did you test with Redirect directive?

Redirect 404 /index.html means that a 404 response will return when the client request /index.html (even if it could possibly exist).

ErrorDocument 404 /index.html means that when the client access a non exist URL, Apache will redirect to index.html page.

You must use ErrorDocument in this case.

share|improve this answer

The two are generally unrelated. When I just tried to set up a redirect with a 404 status I got the error message Redirect URL not valid for this status when trying to start apache.

A Redirect sends the client to a new address and provides a status for the client. The status returned are usually 30x values.

The ErrorDocument directive configures apache to return a particular page (rather than the default page) when an error of type nnn occurs. In your example you are saying return /index.html when a 404 (Not Found) error occurs.

What are you trying to achieve ?

share|improve this answer

If you configure the ErrorDocument directive correctly, all you have to do is make sure the file is not actually present. If you are trying to match a filename pattern, then you need to match the pattern and rewrite the request to a non-existant response. And make sure to turn off directory browsing:

<VirtualHost *:80>
 Options -Indexes
 ErrorDocument 404 /not-found.htm
 AliasMatch /index\.* /something/not/here
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.