Forum Discussion
DM_5174
Nimbostratus
Feb 08, 2011HTTP REDIRECT AND KEEPING URI AFTER DOMAIN NAME
Hi All,
I was wondering if I can get a little help here. I have an existing irule that will redirect and add the "www" if
users forgets to put this in...so if they type "http://mysite.com", it will redirect them to "http://www.mysite.com".
The question here is, I have two additional link that was recently added, so when users add "/app1" or "/app2"
it does not keep this URI but just redirect them back to "www.mysite.com".
What we want to accomplish is: (The URI should be a variable, so this can be anything after www.mysite.com/...."
user enters: http://mysite.com/app1 should get redirect to: http://www.mysite.com/app1
Should NOT happen (URI "app1" is lost or any variable in the future): http://mysite.com/app1 --> http://www.mysite.com
In the future the "/app1" can be anything...we would like to keep this like http://www.mysite.com/$variable
Also, keep existing functionality when user enters "http://mysite.com" --> STILL REDIRECTS TO --> http://www.mysite.com
Thanks for everyone's help.
EXISTING IRULE
when HTTP_REQUEST {
if { [HTTP::host] equals "mysite.com" } {
HTTP::redirect "http://www.mysite.com"
} else {
pool WEB_HTTP_POOL1
}
}
3 Replies
Sort By
- George_Watkins_Historic F5 AccountHi DM,
when HTTP_REQUEST { if { [HTTP::host] equals "mysite.com" } { HTTP::redirect "http://www.mysite.com[HTTP::path]" } else { pool WEB_HTTP_POOL1 } }
- DM_5174
Nimbostratus
Hi George, - hoolio
Cirrostratus
George's iRule should definitely redirect requests with a hostname of mysite.com to www.mysite.com with the original path appended to the redirect. You might want to change [HTTP::path] to [HTTP::uri] to preserve any query string the client uses. If this isn't working for you, try adding debug logging to the iRule to see what the client is requesting. Note I've left off the else clause as the default will be to use the virtual server's default pool.when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]" if { [HTTP::host] equals "mysite.com" } { log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to http://www.mysite.com[HTTP::uri]" HTTP::redirect "http://www.mysite.com[HTTP::uri]" } }
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