Forum Discussion
Jeff_Unger_1067
Nimbostratus
Dec 21, 2005Strip leading www
We have some special needs customers who do not realize that you can reach a website without adding a leading "www" to the URL. So, in order to accomodate those folks, we have aliases setup in DNS. For example: www.excel.gosolo.com is just a CNAME record that points to excel.gosolo.com.
My goal is to strip the leading "www" from the HTTP header whenever it is encountered for the clients I mentioned. I know this can be done using a redirect irule, which is what I am doing now.
when HTTP_REQUEST {
if { [HTTP::host] equals "www.excel.gosolo.com" } {
HTTP::redirect "http://excel.gosolo.com"
}
}
But can it be done using a replace instead? There is no need to do a redirect since it will go to the same IP address, and it actually is causing problems with another part of our site, so I tried the following irule:
when HTTP_REQUEST {
if { [HTTP::host] equals "www.excel.gosolo.com" } {
HTTP::header replace "excel.gosolo.com"
}
}
That did not work. Any ideas?
Thanks,
- You'll need to specify the header name in your assignment.
when HTTP_REQUEST { if { [HTTP::host] equals "www.excel.gosolo.com" } { HTTP::header replace "Host" "excel.gosolo.com" } }
when HTTP_REQUEST { if { [HTTP::host] starts_with "www." } { HTTP::header replace "Host" [string range [HTTP::host] 4 end] } }
- Jeff_Unger_1067
Nimbostratus
Thanks Joe, - The only way to change the URL in the browser is with a redirect. The header replace, will modify the Host HTTP header that is sent to the backend server. So, the backend server will "think" that the browser requested your replaced domain while it really didn't.
- Jeff_Unger_1067
Nimbostratus
Actually, your second suggestion, the more generic recommendation, worked like a charm! The URL shows up in the browser as http://excel.gosolo.com when the irule was applied. - Glad to be of some help.
- Jeff_Unger_1067
Nimbostratus
Turns out I had to use redirect afterall.
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