Forum Discussion
Russell_Findley
Nimbostratus
Jan 23, 2006Redirect Rule from WWW to Unique URL
I am unable to train our customers to stop using WWW in front of their url so I wanted to write a rule to redirect them, but I need some help with the syntax.
I'm trying to do the following....
Martin_Machacek
Jan 26, 2006Historic F5 Account
Russell,
Let's step back first for a second ... so, what you want to do is redirect requests to https://www.x.foo.com to https://x.foo.com, right?
If you don't mind "redirecting" also http://www.x.foo.com to http://x.foo.com and assuming that you are in control of your DNS domain, then the absolutely easiest way how to do that is to change the DNS entry for www.x.foo.com to be an alias (PTR) for x.foo.com, or at least resolve to the same address (address of x.foo.com) and it does not matter whether user put http://www.x.foo.com or http://x.foo.com to the URL (assuming that your original servers are not doing any funky matching on the Host header in requests).
OK, if you cannot use the solution above, then you can do redirection on the BIG-IP, but in case of HTTPS, you'd have to configure the BIG-IP to terminate the SSL connections (i.e. use the SSL proxy). Otherwise BIG-IP cannot see the content of the connection because it is encrypted and cannot issue the redirect.
Assuming that you've configured SSL proxy and make it direct traffic to the same virtual that handles HTTP connections for the same address, and assuming that only www.x.foo.com resolves to the address of the proxy (HTTPS case) which is the same as the address of a port 80 virtual (I further denote the address as , then the configuration can be as easy as this:
rule redirect_to_x.foo.com {
redirect to "x.foo.com" + http_uri
}
virtual :80 {
use rule redirect_to_x.foo.com
}
proxy :443 {
target virtual :80
}Why it works without matching the hostname? Because the client has to do DNS resolution for www.x.foo.com to figure out to which address to connect. So, only clients that requesting http://www.x.foo.com/ connect to the virtual server and there is no need to match the http_host. Similarly only clients requesting https://www.x.foo.com/ connect to the proxy.
If there are multiple DNS names that resolve to (i.e. a virtual hosting scenario), then you need to match the hostname and your rule needs to look like this:
rule redirect_to_x.foo.com {
if(http_host == "www.x.foo.com") {
redirect to "x.foo.com" + http_uri
} else {
use pool
}
}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