Forum Discussion
Pav_70755
Nimbostratus
Oct 26, 2010HTTP Re-Direct and keep original URL in address bar
I have the following simple re-direct in place
}
elseif { [HTTP::host] == "www.domain.com }{
HTTP::redirect "http://www.abc.com/subject"I basically want the address bar to keep www.domain.com when displaying www.abc.com/subject
Any help much appreciated.
Thanks
Pav
14 Replies
- hoolio
Cirrostratus
Hi Pav,
If you want to preserve the existing domain in the URI, you'd need to rewrite the host and/or URI to the new value. This is instead of the HTTP redirect which causes the browser to update the address bar.
The proxypass iRule performs this type of functionality:
http://devcentral.f5.com/wiki/default.aspx/iRules/proxypass
http://devcentral.f5.com/wiki/default.aspx/iRules/proxypassv10
If you don't need all of that functionality, you can use HTTP::header replace Host "newhost" and HTTP::uri "/newuri" to rewrite the host and URI.
Aaron - Pav_70755
Nimbostratus
Thanks Aaron I have about 80 or do re-direct rules in that particular i-rule so I don't want to replace the host header for all of the re-directs just this one in particular? - hoolio
Cirrostratus
Is www.abc.com routable through LTM? Is it a server or pool that you can load balance to? Do you want to send requests which you don't rewrite to a different pool?
Aaron - Pav_70755
Nimbostratus
Yep www.abc.com has just been set up with a dns entry to point to a virtual server on the LTM along with 80 or so other dns entries which require simple http re-directs.
I just need to be able to keep www.abc.com in the address bar after it has re-directed but just for that domain not the other 79! - Pav_70755
Nimbostratus
I've come across this [url=http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/afpg/2/aft/32977/aff/5/afv/topic/showtab/groupforums/Default.aspx]thread'>Click Here
and created the following:when HTTP_REQUEST priority 100 { set http_host [string tolower [string trim [getfield [HTTP::host] ":" 1]]] general URI redirecting switch $http_host { www.domain.com { HTTP::redirect http://www.abc.com/subject } "support.abc.com" { HTTP::redirect http://www.abc.com/subject } return } } }
However this just re-directs as per normal and doesnt keep www.domain.com in the address bar.
any help much appreciated.
Thanks
Pav - hoolio
Cirrostratus
Hi Pav,
If you want to preserve the URL in the address bar, you don't want to send a redirect back to the client. Instead, you'll need to rewrite the HTTP host header and/or URI and possibly select a different pool if the virtual server's default pool doesn't serve content for the separate hostname. Here's a first try at what you're looking for:when HTTP_REQUEST { Check if requested host is domain.com or www.domain.com switch [string tolower [HTTP::host]] { "www.domain.com" - "domain.com" { Matched the hostname, so rewrite the host header HTTP::header replace Host "www.abc.com" Select different pool for this request? pool www.abc.com_http_pool } } }
If (or more likely, when) this doesn't work, can you use a browser plugin like HttpFox for Firefox or Fiddler for IE, to track what's happening?
Thanks, Aaron - Pav_70755
Nimbostratus
Thanks Aaron when i tried that rule i got "Bad Request (Invalid Hostname)
output from httpfox
(Request-Line)GET / HTTP/1.1
Hostwww.domain.com
User-AgentMozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12
Accepttext/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Languageen-us,en;q=0.5
Accept-Encodinggzip,deflate
Accept-CharsetISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive115
Connectionkeep-alive
CookieBIGipServerWeb_Farm_Front=237633546.20480.0000
Bad Request (Invalid Hostname) - hoolio
Cirrostratus
There are two likely causes of the invalid hostname error. Either the host header replacement is using the wrong value, or the request is going to the wrong pool.
Do the servers for www.domain.com answer requests for the www.abc.com content also? If they don't, you need to create a separate www.abc.com pool and uncomment that command in the rule. If you're switching pools based on HTTP request criteria, you should also use a OneConnect profile on the VS. If you're using SNAT on the VS, you can use the default OneConnect source mask of 0.0.0.0. If you're not using SNAT, you can use 255.255.255.255. See the wiki page for details:
http://devcentral.f5.com/wiki/default.aspx/AdvDesignConfig/oneconnect.html
Aaron - Pav_70755
Nimbostratus
Hi Aaron,
Currently all re-directs are going to a pool of for web servers so are you saying i need to create a new pool with these servers in order to re-direct this specific request?
Thanks
Pav - hoolio
Cirrostratus
Hi Pav,
Do all servers in the pool have the same host header set in the web server virtual host definition? Is that what you've put in the iRule in replacement of www.abc.com?
Put another way, if you make a request directly to the pool members, what host name(s) do you have to use to get a valid response from the server?
To answer your question, no the iRule doesn't require you to change the pool. I put that in the example in case you did have two different sets of web servers in two different pools.
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
