Forum Discussion

Steven_Fulton_1's avatar
Steven_Fulton_1
Icon for Nimbostratus rankNimbostratus
Feb 23, 2015
Solved

How to set up http 301 response

Here is my problem. Our web server administrator has a website:

 

which is currently hosted by a vendor they will no longer use once the site is retired.

 

He is going to make a new site called

 

hosted by a different vendor.

 

When siteB is ready they want siteA to return a 301 redirect to siteB. They do not want to do this usign the site A vendors server. They also do not simply want to point the DNS for siteA.company.com to the same server as siteB using an A record or a CNAME record. A 301 redirect is their preference so that search engines will be updated.

 

Is this possible to do on the F5 LTM? If I set up a virtual server, point the DNS entry for SiteA at the virtual server, and then have the F5 redirect the users to siteB?

 

I know this would be fairly simple to do using an apache web server but I would prefer to use the F5 so that I don't have to provision a web server just to do a redirect. I am having a hard time figuring out the syntax that would be needed to do this with an irule. My searches into this question have so far turned up conflicting and unclear answers. If this is possible, can someone please explain it to me using the example names above? Thanks.

 

  • once you create a new virtual server for siteA, assign an iRule like:

    when HTTP_REQUEST {
      HTTP::respond 301 Location "http://siteB.company.com"
    }
    

    you could also do the same redirect using the same virtual server that you are using for siteB, assuming it's not HTTPS (certificate SANs would need to include siteA.company.com to avoid browser trust error), but the iRule would be:

    when HTTP_REQUEST {
      if {[string tolower [HTTP::host]] equals "sitea.company.com"}{
        HTTP::respond 301 Location "http://siteB.company.com"
      }
    }
    

    if the URI structure is going to be the same between the two sites, I recommend tacking on [HTTP::uri] to the redirect so users don't have to re-navigate to the URL they originally requested:

    HTTP::respond 301 Location "http://siteB.company.com[HTTP::uri]"
    

4 Replies

  • shaggy's avatar
    shaggy
    Icon for Nimbostratus rankNimbostratus

    once you create a new virtual server for siteA, assign an iRule like:

    when HTTP_REQUEST {
      HTTP::respond 301 Location "http://siteB.company.com"
    }
    

    you could also do the same redirect using the same virtual server that you are using for siteB, assuming it's not HTTPS (certificate SANs would need to include siteA.company.com to avoid browser trust error), but the iRule would be:

    when HTTP_REQUEST {
      if {[string tolower [HTTP::host]] equals "sitea.company.com"}{
        HTTP::respond 301 Location "http://siteB.company.com"
      }
    }
    

    if the URI structure is going to be the same between the two sites, I recommend tacking on [HTTP::uri] to the redirect so users don't have to re-navigate to the URL they originally requested:

    HTTP::respond 301 Location "http://siteB.company.com[HTTP::uri]"
    
    • Steven_Fulton_1's avatar
      Steven_Fulton_1
      Icon for Nimbostratus rankNimbostratus
      Thanks so much shaggy. In the examples that I was looking at before, that was the part [HTTP::uri] that was confusing me. Thanks for explaining what that does.
  • once you create a new virtual server for siteA, assign an iRule like:

    when HTTP_REQUEST {
      HTTP::respond 301 Location "http://siteB.company.com"
    }
    

    you could also do the same redirect using the same virtual server that you are using for siteB, assuming it's not HTTPS (certificate SANs would need to include siteA.company.com to avoid browser trust error), but the iRule would be:

    when HTTP_REQUEST {
      if {[string tolower [HTTP::host]] equals "sitea.company.com"}{
        HTTP::respond 301 Location "http://siteB.company.com"
      }
    }
    

    if the URI structure is going to be the same between the two sites, I recommend tacking on [HTTP::uri] to the redirect so users don't have to re-navigate to the URL they originally requested:

    HTTP::respond 301 Location "http://siteB.company.com[HTTP::uri]"
    
    • Steven_Fulton_1's avatar
      Steven_Fulton_1
      Icon for Nimbostratus rankNimbostratus
      Thanks so much shaggy. In the examples that I was looking at before, that was the part [HTTP::uri] that was confusing me. Thanks for explaining what that does.