Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Doing a proper 404 redirect

by DStaal (Chaplain)
on Mar 23, 2010 at 20:27 UTC ( #830391=note: print w/ replies, xml ) Need Help??


in reply to Doing a proper 404 redirect

Typically, if at all possible, you'd want to do this through Apache. (Which will, always, have a default 404 page. It may have one or more custom pages as well.)

Doing it even via a CGI script is likely to cause problems with someone, as you aren't really putting it into the HTTP response header, but into the payload. It'll work sometimes, in some browsers, but I'd check to make sure you can't set up a real one first.


Comment on Re: Doing a proper 404 redirect
Re^2: Doing a proper 404 redirect
by DreamT (Pilgrim) on Mar 24, 2010 at 07:56 UTC
    Well, I'm building an architecture where Perl is supposed to handle 301:s and 404:s, opposed to handling "everything" via .htaccess (I don't like to write .htaccess dynamically)

    But maybe .htaccess is the only way to go? I know it's not Perl related but...Maybe RewriteMap is a possible solution?

      I think you have a problem understanding the HTTP protocol.

      Imagine you knock on a door and ask for a photo of a certain teddy bear. This is a HTTP request. Now, you could get some different responses:

      Human behind the doorStatus CodeStatus Text from RFC 2616Notes
      "OK, here you are", and hands over a pretty image200OK
      "Do you want a picture of it in the green shorts? Or with the new stylish jeans? Or in the fluffy dress? Or ..."300Multiple Choices
      "Sorry, I gave the teddy to the son of my neighboor just over the street. Ask him."301Moved PermanentlyNote that you will never see the teddy bear here again.
      "Hmm, let me think. Where did I put it? Hmmm... - Oh right, it's at the neighboor next door."302FoundNo information about how long the teddy bear will stay there.
      "Walk around the house, I'll give it to you through the front door"303See OtherRFC: For redirects from POST to GET
      "Oh, right, that teddy bear. My son has carried it into the basement, go there and ask him".307Temporary RedirectThe teddy will come back here.
      "┐Hablas espa˝ol? Parlez-vous franšais? Sprechen Sie deutsch?"400Bad Request
      "Let me see your ID card first, please"401Unauthorized
      "Hand over the money first"402Payment RequiredNo, I'm not kidding. But as no one has a working concept for payments inside HTTP, the code description has changed to "reserved for future use".
      "YOU, Sir, won't get that from me."403Forbidden
      "I don't have no stinkin' bears."404Not FoundNot here, no information if it was here before or will be here later.
      "The bear photographer? No, he doesn't live here any more. Don't know where he's gone."410GoneGone, and won't come back, like 301. But no new URL known, so no redirection.
      ***KABOOOOOM***500Internal Server Error
      "Sorry, I don't have a polaroid."501Not Implemented
      "My parents are not at home. Please come back later!"504Service Unavailable

      Is it clear now?

      What answer do you want to give? 404 means "I don't have that, and I don't know where it is." No Redirection. 301/302/303/307 means "OK, I don't have it here, but look over there." with minor differences in WHY you don't have the requested resource. Redirection follows automatically. Or the really hard 410? "It is no longer here, and it won't come back."

      Why do you think that search engines or customers need a special treatment? If a resource is not available, send 404 or perhaps 410. If it is elsewhere, send 301/302/303/307.

      If you want to help humans navigating your page when they hit a 404 page, you could add a search form, a link to a search page, a link to a site map, or links to the most wanted pages to the 404 page. Just make sure that the 404 page is larger than 1024 bytes, or else MS IE users will only see a braindead default page generated by the MS IE.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Thanks for your reply!
        Obviously, i've mixed this up with another subject:-) I wasn't supposed to talk about rewritemaps and such at all...

        The purpose of my 404:s aren't of course to redirect to another page, only to express that "this page didn't exist".

        I understand what you're writing, obviously I can print whatever content I want to, my concern is just that i want to write a correct 404 header before that.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://830391]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (6)
As of 2014-09-17 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (62 votes), past polls