Forum Discussion

Dayton_Gray_103's avatar
Dayton_Gray_103
Icon for Nimbostratus rankNimbostratus
May 16, 2008

Send 404 and redirect?

I have this irule:

 

 

 
  HTTP_RESPONSE { 
   if { [HTTP::status] == "404"} { 
     HTTP::redirect "http://www.mysite.com/error/nopagehere.html" 
  } 
 } 
 

 

 

Is there anyway to send a 404 status code to the browser and redirect to this page? The reason I need this is so that my nopagehere.html link doesn't get listed on search engines as a valid page HTTP::redirect is just issuing a 302 redirect to this page.

 

 

Thanks in advance!
  • I don't think so. A redirect is defined by a 301 or 302 HTTP response with the new address in the "Location" HTTP response header. The 404 HTTP response does not have redirection defined as part of the response.

     

     

    Anyone else have any ideas on this one?

     

     

    -Joe
  • Would I be able to exclude the search engine user-agents in this iRule? That would probably help the situation out. I know this can be done in an HTTP_REQUEST but not sure how it would behave in an HTTP_RESPONSE.

     

     

    -Dayton
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    I'm not quite sure I follow what you're trying to do. I think what you're looking for is to inspect the user agent on the inbound request, then check that value on the response to help determine an action? If so this should be pretty straight-forward. The user-agent should be cached for the duration of the iRule's execution (the whole connection) or you could store it simply in a local variable like:

     
     set agent [HTTP::header" User-Agent"] 
     

    Colin