Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 *.example.com
    Redirect 404 /index.html
    ErrorDocument 404 /index.html
</VirtualHost>

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

share|improve this question
add comment

3 Answers 3

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
add comment

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
add comment

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
</VirtualHost>
share|improve this answer
add comment

Your Answer

 
discard

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.