Forum Discussion

OttimoMassimo_1's avatar
OttimoMassimo_1
Icon for Nimbostratus rankNimbostratus
Nov 08, 2010

HTTP re-write

Hi,

 

 

Apologies in advance for the newbie question!

 

 

I'd like to apply a HTTP re-write so when a user browses to blog.site.com they are redirected to www.site.com/blog/, but blog.site.com remains in the user's address bar.

 

 

I can currently redirect from blog.site to www.site.com/blog/ with the configuration below. Unfortunately www.site.com/blog appears in the address bar of the browser after the redirect. Is it possible to "re-write" to a new URL in the manner I've outlined?

 

 

when HTTP_REQUEST

 

....

 

 

switch [HTTP::host] {

 

 

"blog.site.com" {

 

HTTP:redirect "http://www.site.com/blog/"

 

}

 

 

4 Replies

  • Hi OttimoMassimo,

     

    There are 2 ways to ago about this.

     

     

    Do you want the user who enters blog.site.com to be redirect to www.site.com/blog but still retain the blog.site.com on the user's URL on the browser?

     

     

    If so then your code would look something like this.

     

     

     

    
    HTTP_REQUEST {
          switch -glob [HTTP::host] {
          "blog.site.com" {
                  HTTP::header replace Host "www.site.com" 
                  HTTP::uri /blog [HTTP::uri]
                 }
          }
    }
    

     

     

     

     

    or

     

     

     

    Do you want to a user who enters blog.site.com to be redirected to www.site.com/blog, but have www.site.com/blog on the user's URL on the browser?

     

     

    If so then the code would look something like the following:

     

     

    
    HTTP_REQUEST {
            switch -glob [HTTP::host] {
            "blog.site.com" { HTTP::redirect http://www.site.com/blog/ }
            }
    }
    

     

     

     

    I hope this helps

     

    Bhattman
  • You could also use the ProxyPass iRule for this:

     

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/proxypassv10

     

     

    Aaron
  • so yeah, got this working in the end with the following:

     

     

    when HTTP_REQUEST {

     

    ...

     

    switch [HTTP::host] {

     

    "blog.site.com" {

     

    if { [HTTP::uri] equals "/" } {

     

    HTTP::uri "/blog/"

     

    }

     

    pool

     

    return

     

     

    It was grafted into an existing i-rule which had a couple of re-writes before defaulting to the default pool