Forum Discussion

Jason_44064's avatar
Jason_44064
Icon for Nimbostratus rankNimbostratus
Sep 30, 2011

Changing Host URL without Redirect - IRULE

Hey all,

 

 

I have been poking around the forums and couldn't find the exact answer to the IRULE i would like to write; or if its even possible to write this rule.

 

 

 

Here's my scenario. A user enters gear.swimming.com, I want the IRULE to change the HOST URL from gear.swimming.com to www.recreation.com/swimming while viewing the content of gear.swimming.com.

 

 

 

 

 

I'm doing this because I want to optimize my SEO's.

 

 

 

Thank you for you time and assistance.

 

  • Hi Jason,

    Yes you can do that with a HTTP::header replace of the HTTP::host value. There is an example here:

    http://devcentral.f5.com/wiki/iRules.HTTP__host.ashx

     
    when HTTP_REQUEST {
    if { !([string tolower  [HTTP::host]] equals "www.foo.com") } {
    HTTP::header replace Host "www.bar.com"
     You may or may not need to redirect the traffic to a different pool
     depending on your applicaiton setup
    pool alternate.website.pool
    }
    }
    

    Hope this helps.
  • Thanks for the quick reply Michael,

     

     

    That didn't seem to work. I looked in the IRULE stats and it hasn't processed any rules.
  • I must have misread what you were needing.

    In order to change the Browser URL from "gear.swimming.com" to "www.recreation.com" you are going to have to redirect. A 301 or 302 is your choice.

    HTTP::redirect "http://www.recreation.com/swimming" = 302

    HTTP::respond 301 Location "http://www.recreation.com/swimming" = 301

    If www.recreation.com is using an alternate Virtual Server you will need to un-comment the bottom section and aim this iRule at the pool of servers that serve content for gear.swimming.com.

    The HTTP::header replace will take care of any Host Header Issues.

    If the content for gear.swimming.com is in the root directory of the site on the servers you will need to remove the "/swimming" URI, but allow any sub-directories to still function properly.

    Try this and see if it works for you:

     
    when HTTP_REQUEST {
     If sites exist on the same Virtual Server, this will change the Browser URL and redirect back to this
     Virtual Server.  If they occupy seperate Virtual Servers it will redirect the traffic away from this
     Virtual Server and the iRule will need to be split.  First if on one Virtual Server, Second if on the
     Second Virtual Server.
    if { [HTTP::host] eq "gear.swimming.com" } {
    HTTP::redirect "http://www.recreation.com/swimming"
    }
    if { [string tolower  [HTTP::host]] equals "www.recreation.com" && [HTTP::uri] starts_with "/swimming" } {
     In case of Host Headers, replace the Host Value
    HTTP::header replace Host "gear.swimming.com"
     Remove /swimming subdirectory
    HTTP::uri [URI::path [HTTP::uri] 1 1]
     You may or may not need to redirect the traffic to a different pool depending on your applicaiton setup
    pool gear.swimming.com.server.pool
    }
    }
    
  • recreation.com/swimming is basically a dummy directory created for SEO purposes. (assuming this all works out)

     

     

    The only true content we have is gear.swimming.com.

     

     

    Also, recreation.com/swimming is not behind the F5s, as it is located in an external hosted environment.

     

     

    Not sure if this changes anything.

     

     

     

    gear.swimming.com >> F5 Rewrites Host Header to display >> recreation.com/swimming

     

     

     

    Gear.swimming.com = in F5 environment

    Recreation.com = in External Hosting Environment

     

     

    Thanks again.

     

  • OK. I believe that I understand. If the User Enters: gear.swimming.com you want the browser to display: recreation.com/swimming while showing the content for gear.swimming.com.

     

     

    The only way to change the Browser URL is through a redirect (you can mask the URL or URI to the server at will, but the Browser does a DNS Lookup to resolve the DNS Name to the IP Address). As soon as you redirect to change the browser URL you would no longer be in control in your situation and the External Hosting company takes over. The External Hosting company would then have to manipulate the sub-directory (/swimming) to look back at your system to get the content for gear.swimming.com.

     

     

    Basically, they would have to do what you are trying to do from their end.

     

  • That's correct Michael.

     

     

    Is there anyway of doing this without redirects?

     

     

    For the F5 side, would the code you supplied above do the job for the F5 box?

     

     

    will recreation.com domain get the credit in terms of SEO?

     

     

    Thanks!

     

  • Is there anyway of doing this without redirects?

     

    No. Not in the configuration that you described (gear.swimming.com being hosted behind an F5 and recreation.com/swimming being hosted by a Third Party). In this scenario you are going to have to talk to one or the other. If the situation was reversed (recreation.com/swimming was hosted behind an F5 and gear.swimming.com had the content and was hosted by a Third Party), you could get it to work.

     

     

    For the F5 side, would the code you supplied above do the job for the F5 box?

     

    In your scenario, no. In the reverse scenario mentioned above, yes.

     

     

    will recreation.com domain get the credit in terms of SEO?

     

    In your scenario gear.swimming.com will be the URL that you must use to see the content, so it will get the credit. In the reverse scenario, yes because the requests would be proxied through the F5 and then returned to the user.
  • I think Jason wants clients to access gear.swimming.com and have LTM proxy requests to www.recreation.com/swimming. This is possible to do with the ProxyPass iRule:

     

     

    http://devcentral.f5.com/wiki/iRules.proxypassv10.ashx

     

     

    Aaron