Forum Discussion
theizer_91634
Nimbostratus
Sep 22, 2010simple redirection not working as expected - please help
I need requests to http://website.com to be redirected to http://www.website.com (which also needs to be redirected to https)
Here is the irule I created to do this:
when HTTP_REQUEST {
if {[HTTP::uri] equals {website.com}} {
HTTP::uri {www.website.com}
} else {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
When I applied this and opened http://website.com it just redirected to https://website.com. I used the iRule Redirection generator to create the first part of the if/else but it doesn't appear to be triggering off http://website.com like I thought it would.
Please help a newbie out.
Thanks!
- Chris_Miller
Altostratus
There are two main parts to a common url like "http://website.com."when HTTP_REQUEST { if { [string tolower [HTTP::host]] eq "website.com"} { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
- Joel_Moses
Nimbostratus
The HTTP::uri function doesn't actually contain the hostname, just the path. You're looking for: - theizer_91634
Nimbostratus
F5 support hooked me up and fixed my irule. Thanks guys!
when HTTP_REQUEST { if {[HTTP::host] equals "website.com"} { HTTP::redirect "https://www.website.com[HTTP::uri]" } else { HTTP::redirect "https://[HTTP::host][HTTP::uri]" } }
- hoolio
Cirrostratus
That iRule should have the same effect regardless of the requested host. So you should be able to simplify the rule a bit and always redirect to https://[HTTP::host][HTTP::uri] without checking the requested host.when HTTP_REQUEST { HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
- Chris_Miller
Altostratus
Theizer...do you want to redirect all traffic to https even if it isn't website.com? Or did you just want to redirect website.com to https://www.website.com? - hoolio
Cirrostratus
Sorry, Chris. I think I misread the original intent. I'm guessing the original poster is trying to handle example.com and www.example.com resolving to the same IP with a single cert valid only for www.example.com. So maybe it would be safer to redirect all requests to https://www.example.com[HTTP::uri] rather than using [HTTP::host] to insert the originally requested host in the redirect?
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