Forum Discussion
ukitsysadmin_95
Nimbostratus
Jun 04, 2009redirect example.xx to www.example.xx
Hello
I'm new to irules, and would love some help on creating an irule for my problem below
Our web farm hosts a single domain name, but multiple geographic suffix's. e.g.
example.co.uk
example.be
example.fr
example.se
Now our back-end database will only accept www.example.xx (xx = country suffix)
So what we have to do is the following
DNS A records for
www point straight to our web farm (the database will accept www.example.xx)
But for anyone who uses the url, without www
example.co.uk
example.be
we have a standalone web server that redirects the url example.xx to www.example.xx for our site to work
I know irules can do this but I haven't a clue on where to start, this will improve performance and remove the single point of failure being the standalone web server
can anyone please help ????
many thanks in advance
5 Replies
- Colin_Walker_12Historic F5 AccountSo all you need to do is redirect anything that comes in without www to the www prepended version?
That's straight-forward:when HTTP_REQUEST { if { !([HTTP::host] starts_with "www.") } { HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } }
This will take any request coming in to a domain that does not begin with www., and redirect it to the exact same place, but with www. at the beginning of the host name. Of course, this would apply to all domains. If you wanted to limit it to just the domains you listed you could add in a switch statement or a class search, something like that.
Is this what you were looking for?
Colin - ukitsysadmin_95
Nimbostratus
Hi Colin,
thats great thanks, how would you add in a swtich statement or class search of data list group, so it make it easier to add domains, etc, etc
thanks again
James - JRahm
Admin
This is domain independent, [HTTP::host] returns the domain that was submitted, and then just prepends www. to it. Now, if you're going to redirect to different domains/uri's based on source, welll that's a different story. Can you provide an example scenario? - ukitsysadmin_95
Nimbostratus
What i'm wanting to achieve, is the following
just say over the years we have numerous different domains that all used to display different web sites and now we want all the old domain names to point and re-point to their local geographical web site
from my first post, our database will only except these address:
www.abc.co.uk
www.abc.nl
www.abc.be
so on and so on
So I want to redirect any abc.xx to www.abc.xx (xx being geographical suffix)
for example, our main UK site is www.abc.co.uk
all our old domains that we want to repoint would be
abc.co.uk
www.zxy.co.uk
zxy.co.uk
def.co.uk
www.def.co.uk
ghk.co.uk
www.ghk.co.uk
then the same for our dutch sites, www.abc.nl
abc.nl
www.zxy.nl
zxy.nl
def.nl
www.def.nl
ghk.nl
www.ghk.nl
if its possible, can we use a "data list group" to make administering all these domains eaiser in thr future ?
I hope this all makes sense - hoolio
Cirrostratus
If you only want to redirect domains which are listed in a datagroup, you could define them in a datagroup in lowercase and then use an iRule like this:when HTTP_REQUEST { Check if Host header is present with a length if {[string length [HTTP::host]]}{ Save host header value in lowercase set host [string tolower [HTTP::host]] Check if Host header does not start with www if {!($host starts_with "www.")}{ Check if host is listed in the domain datagroup if {[matchclass $host equals $::domains_to_redirect]}{ Redirect client to same URI but with www prepended to the host header value HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } } } }
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
