Forum Discussion
Joe_Pipitone
Nimbostratus
Dec 23, 2009Rewrite at the root of the domain
I have a rewrite rule that I'm already using to redirect the beginning of a domain request while keeping the URI as the user typed it in.
I want to redirect all requests to our-website.com/insert_uri_here to another-website.com/insert_uri_here
Will this work correctly? I need to make sure I catch all requests from the root as well as any other pages below so:
http://our-website.com/page.aspx rewrites to http://another-website.com/page.aspx, as well as http://our-website.com/
when HTTP_REQUEST {
evaluate characters as lower case
Pass characters back to server in lower case
set my_uri [string tolower [HTTP::uri]]
if { $my_uri starts_with "/" } {
redirect to our-website.com/images on matching URI
HTTP::redirect http://another-website.com$my_uri
}
}
I just want to make sure that the line if { $my_uri starts_with "/" } { is going to correctly catch these requests
- L4L7_53191
Nimbostratus
Are you looking to only redirect based on the hostname? If so, you can issue the redirect like:HTTP::redirect http://another-website.com[HTTP::uri]
- Joe_Pipitone
Nimbostratus
Something else needs to happen too - I'm not sure this is possible? - The_Bhattman
Nimbostratus
Hi Joeseph,when HTTP_REQUEST { if { ([HTTP::host] eq "our-website.com") } { switch -glob [string tolower [HTTP::uri]] { "/" { HTTP::redirect "http://another-website.com/portals/water.aspx" } default { HTTP::redirect "http://another-website.com/[HTTP::uri]" } } }
- Joe_Pipitone
Nimbostratus
It does - but in the part of your rule where you are specifying /anyfolder/anypage.aspx, how can I catch any uri passed? Can I use set my_uri [string tolower [HTTP::uri]] somehow and then $my_uri? - The_Bhattman
Nimbostratus
Yes you can use my_uri. However, why create another variable when you don't need it - at least in the example I shown above. - Joe_Pipitone
Nimbostratus
Thank you - it works great! I appreciate your help. - Joe_Pipitone
Nimbostratus
One question - it seems as though this rule is working, however if a user places a www in front of the domain name, it doesn't seem to catch it and redirect / rewrite:when HTTP_REQUEST { if { ([HTTP::host] eq "old-site.com") } { switch -glob [HTTP::uri] { "/" { HTTP::redirect "http://newsite.com/portals/water.aspx" } default { HTTP::redirect "http://newsite.com[HTTP::uri]" } } } }
- L4L7_53191
Nimbostratus
The match is literal - you've used 'eq' here. So www.old-site.com != old-site.com. You can use 'contains' instead, which is greedier and should match both.
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