Forum Moderators: phranque

Message Too Old, No Replies

am I displaying a 404 error message correctly using .htaccess

         

arbitrary

3:07 am on May 22, 2006 (gmt 0)

10+ Year Member



I'm using an .htaccess file as follows to show a custom page for pages that are not found on the server. When pages are not found, I would like give a 404 response and then direct the visitor to /missing.html

In .htaccess, I am using:

ErrorDocument 404 /missing.html

When a page is not found, they are directed to missing.html

This works in that missing.html is displayed when a page is not found. Additionally, in the title bar of my browser, a 404 error is displayed when I am directed to missing.html.

I checked to see if this is working using a header checker tool and now I am not sure if this is working.

I wanted to use the header checker tool at searchengineworld (webmasterworld) but that tool is no longer accessible, so I used a couple of other tools instead.

One tool, showed me two responses. The first response was a 301 response and second response was a 404 error code. I don't know why there were two responses or what two responses mean.

The second tool showed only one response, a 301 response.

I thought I was doing this right but I don't think I am anymore.

Can anyone explain why the first tool showed two responses? Am I doing this right, what about the 404?

Thanks.

arbitrary

3:21 am on May 22, 2006 (gmt 0)

10+ Year Member



Please disgregard the above post.

The observations above no longer hold true. I am seeing the proper 404 response on both tools. I believe I was seeing wrong data temporarily as I was trying something else... which leads to the question I had at first.

I would like to use .htaccess to display a 410 response (permanently gone) but then direct to /missing.html.

I thought this would have worked:

ErrorDocument 410 /missing.html

but it does not work.

Can anyone let me know how to use .htaccess to display a 410 response but direct to missing.html.

Thanks.

jdMorgan

3:40 am on May 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You must declare each URL that is Gone, either using the Redirect family of directives in mod_alias, or the RewriteRul directive of mod_rewrite. A 404 is a catch-all response when a resource cannot be found for unspecified reasons. When a file is truly Gone, you have to declare it as such, because you are stating that it was removed intentionally.

Redirect 410 /URL-path-to-removed-file

-or-

RewriteRule ^URL-path-to-removed-file$ - [G]

Redirect uses prefix-matching, while RedirecMatch and RewriteRule use regular expressions. So, you can mark entire directories or groups or classes of URLs matching certain patterns Gone if you desirec.

Jim

arbitrary

4:43 am on May 22, 2006 (gmt 0)

10+ Year Member



Jim, I am following some of what you are saying but I am not getting it all.

First, do these lines go in .htaccess (or do they have to go in httpd.conf, I would like to use .htaccess)?

I also don't understand how the server is directing the user to /missing.html as that is not shown in the two lines above.

Say I have two directories that are both now gone, would I do something like this in .htaccess work?

Redirect 410 /directory-1/
Redirect 410 /directory-2/

If so, how is that directed to /missing.html

Please bear with me, this is foreign to me.

Thanks.

jdMorgan

7:33 pm on May 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




ErrorDocument 410 /missing.html
#
Redirect 410 /directory-1/
Redirect 410 /directory-2/

The first line declares the document to be used to handle 410 responses, while the second two declare that requests for those directories should result in a 410 response.

Jim

arbitrary

8:13 pm on May 22, 2006 (gmt 0)

10+ Year Member



Thanks so much Jim, your help is really appreciated.