Forum Discussion
gerald_wegener_
Nimbostratus
Jun 12, 2006Eliminate redirects
In lieu of doing http redirects in the following example basic example:
--------
Client connects to http://abc.com and is redirected to http://www.abc.com
--------
would it be possible to eliminate the redirect in some fashion. For example:
1. Rewrite the request for abc.com to www.abc.com and submit it to the www.abc.com virtual.
2. Rewrite the response so the client now sees www.abc.com
Running ver 9.x
One goal here is to eliminate the time it takes for the client to get redirected and to reconnect to a new URL.
Thank You.
15 Replies
- hoolio
Cirrostratus
Hello,
There are two similar posts:
Click here
(and was asked again here: Click here)
The first post has some conceptual suggestions. If anyone has more detail to add, please do so. Else, I'll try testing in the next few days and see if I can provide more info on how to rewrite the URI in the request and the HTML content in the response.
Aaron - Colin_Walker_12Historic F5 AccountAll you'd need to do is re-write the hostname when the client is making a request to the server. The server would then return a Location that includes that modified hostname, and subsequent requests should be sent to the address in the Location header.
So all you should really need to do for this particular scenario is:when HTTP_REQUEST { if { not ( [HTTP::host] starts_with "www." ) } { HTTP::header replace Host "www.[HTTP::host]" } }
Since you want the client to see the updated URL, you shouldn't have to do any further work. The Location header sent back from the server should include the www, and the client should update appropriately. If you wanted to hide the re-write from the client, that's where more work on the response side of things would come in.
Colin - gerald_wegener_
Nimbostratus
It's been awhile but I'm back on this. I tried the above iRule but it doesn't seem to rewrite the hostname. Here is the rule I'm using and some log entries that show it's not rewriting the hostname:
when HTTP_REQUEST {
if { [HTTP::host] equals "abc.com" } {
log local0. "orig hostname [HTTP::host]"
HTTP::header replace Host "www.[HTTP::host]"
log local0. "rewritten hostname is [HTTP::host]"
}
}
Aug 10 18:04:36 127.1.1.3 tmm1[2341]: Rule hostname_rewrite : orig hostname abc.com
Aug 10 18:04:36 127.1.1.3 tmm1[2341]: Rule hostname_rewrite : rewritten hostname is abc.com - I've seen this before as well and I believe it just has to do with variable caching within the iRules engine. The header insert is taking place but it isn't updating the value of the HTTP::host variable. Have you verified that the host field being passed to your backend webserver isn't correct? I bet your server logs will show your rewritten value being sent.
-Joe - bl0ndie_127134Historic F5 AccountDoes the actual header that's sent to the server get modified? I wonder if [HTTP::host] is returning the old value.
- gerald_wegener_
Nimbostratus
I checked the backend with a Sniffer and the host header is being re-written. Unfortunetly I don't think this is going to be sufficient for what we trying to accomplish.
-------------------------
There is more to it than this but we would need to be able to redirect (based on some critera) a percentage of new requests (i.e. for the default page) that come into a particular Virtual DIRECTLY to another Virtual. Is this possible? We don't want to do client redirects and we don't want to rewrite the host header since that request which we want to go directly another virtual will first need to hit the Virtual-A pool.
As a note we do this do distribute percentages of new sessions from our our primary Virtual to 2 other Virtuals which are used to test code changes, new products, etc.
For example for 3 Virtuals:
Virtual-A: www.abc.com (main virtual - gets 100% of new connections)
Virtual-B virtb.abc.com (will get some adjustable % of the www.abc.com new sessions e.g. 4%)
Virtual-C virtc.abc.com (will get some adjustable % of the www.abc.com new sessions e.g. 6%) - JRahm
Admin
Is there a reason the traffic MUST hit the other virtuals, or do you just need it to appear that it is? You can create multiple pools that reside behind a single virtual server, using an iRule to switch as necessary. You could use the session table to count current connections, and switch new connections to each pool accordingly with some math processing in your iRule. There are a lot of options... - gerald_wegener_
Nimbostratus
I see your point about using pools in lieu of doing a redirects to other Virtuals. I'll need to check on whether that would be acceptable but let's suppose that it is, would the following be doable using an iRule:
Assume we have a Virtual (Virtual-A) and 3 pools (pool-A, pool-B, and pool-C)
1. A request comes into the Virtual-A for www.abc.com
2. If the cookie "cookieB" exists then sendto pool pool-B
3. If the cookie "cookieC" exists then sendto pool pool-C
4. No cookie was found as indicated. Now determine if this is a NEW session to www.abc.com e.g. someone typed in their browser "www.abc.com / someone hitting the default page, etc. What criteria determines a new session?
5. If it's not a new connection send to pool pool-A
6. If it is a new session then we want to determine, based on percentages of traffic, which pool to send this new session to. As an example to accomplish this we would want to do the following (you may have a better way to do this):
a. Run a Random Number Generator that returns a value between 1 and 100.
b. If the value > 10 then send to pool pool-A (e.g. we want 90% of new sessions go to pool-A) - exit
c. If the value is >=7 the sendto pool-B (e.g. we want 4% of new sessions go to pool-B - Drop a cookie "pool-B" (for future returning traffic) and may want to rewrite the host header - exit
d. Else send to pool-C (remaining value 1-6) so 6% of new sessions go to pool-C - Drop a cookie "pool-C" (for future returning traffic) and may want to rewrite the host header - exit - unRuleY_95363Historic F5 AccountIn this case, I do think the pool chooser approach should be all you need to do though...
- gerald_wegener_
Nimbostratus
Before I start on an actual iRule can you help me with the following:
I'm not sure how to go about determining whether a request is a new session or not and then incorporate that into an iRule.
Also do you have available code for Random Number Generator that I can use?
Thank You.
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