Forum Discussion
Anish_Srivastav
Nimbostratus
Mar 02, 2010URL host rewrite based on URI
Hello guys
I was browsing through the forum and could not come across a similar situation that I am facing. We have a website with following links:
http://www.xyz.com/Product1
http://www.xyz.com/Product2
http://www.xyz.com/Product3
www.xyz.com is setup as a virtual server on the F5. Also, the above URL's have been indexed by various search engines. Now, we want to do the following:
If the request comes to http://www.xyz.com/Product1 then it should get redirected to http://Product1.xyz.com/Product1, now this is not that much of a problem as I can achieve this by setting a Host Header value Product1.xyz.com on the IIS webserver and an irule on the LTM such as:
when HTTP_REQUEST {
if {([HTTP::uri] starts_with "/Product1" and [HTTP::host] equals "www.xyz.com")}
{
HTTP::response 302 location "http://Product1.xyz.com[HTTP::uri]"
}
}
But, now from this page if the subsequent request is to /Product2, the link in the browser shows http://Product1.xyz.com/Product2. I would like the link in this case to be http://Product2.xyz.com/Product2 or in case of Product3 http://Product3.xyz.com/Product3
Is there any simpler way to achieve this rather than multiple if-else statements in the iRule as the Product line will keep on increasing in the future.
TIA
Anish
- hoolio
Cirrostratus
Hi Anish, - Anish_Srivastav
Nimbostratus
Hey Aaron - hoolio
Cirrostratus
So maybe something like this?when HTTP_REQUEST { Check if the subdomain starts with www. or is null if {[string tolower [HTTP::host]] starts_with "www." or [HTTP::host] eq ""}{ Exit this event in this rule return } log local0. "Host didn't start with www: [HTTP::host]" Save the first directory in the HTTP path, set to lower case set first_dir [string tolower [getfield [HTTP::path] "/" 2]] Check if the first directory matches some pattern like "product" if {not ($first_dir starts_with "product")}{ Exit this event in this rule return } log local0. "\$first_dir, $first_dir, matched the pattern check" Check if the first directory in the path is not the same as the subdomain if {$first_dir ne [getfield [string tolower [HTTP::host]] "." 1]}{ log local0. "Redirecting request to $first_dir.xyz.com" HTTP::redirect "$first_dir.xyz.com" } } }
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