Forum Discussion
Mike_Wethington
Nimbostratus
May 01, 2009Redirect domain.com to www.domain.com
When users type http://domain.com i need to redirect them to http://www.domain.com, how do i do this?
8 Replies
Sort By
- Danny_Trinh_197
Nimbostratus
The simplest way is you create an alias in your dns system to point domain.com to www.domain.com. - Mike_Wethington
Nimbostratus
That is already in place, and works. What i need to do is when the request hits my BIG-IP i need to tack on the www. to the domain.com but only if it comes in as http://domain.com. - hoolio
Cirrostratus
Or you can use an iRule:when HTTP_REQUEST { Check if there was a host header value doesn't start with www. and does start with an alphabet character if { not ([string match -nocase www.* [HTTP::host]]) && [string match -nocase a-z* [HTTP::host]]}{ HTTP::redirect "http://www.[HTTP::host]" } }
when HTTP_REQUEST { Check if the host header value isn't www.domain.com if { not ([string tolower [HTTP::host]] eq "www.domain.com") }{ HTTP::redirect "http://www.domain.com" } }
- Mike_Wethington
Nimbostratus
Thanks Aaron, this worked you are the man. - Fotios_30046
Nimbostratus
If they came into a specific url without the www prefix, would you just add the [HTTP::uri]? - hoolio
Cirrostratus
If you rewrite the URI, the client wouldn't necessarily see the update to www.example.com and may end up making a request to https://example.com instead of https://www.example.com causing a cert mismatch error on the browser. - Fotios_30046
Nimbostratus
Good point, I didn't think of that Aaron. - JRahm
Admin
An alternative to the string match, though I'm not sure which is more optimal:when HTTP_REQUEST { if { [HTTP::host] equals [domain [HTTP::host] 2] } { HTTP::redirect "http://www.[HTTP::host]" } }
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