Forum Discussion
Chris_Robert_10
Nimbostratus
Sep 15, 2006URL rewrite plus
I currently have this iRule running:
when HTTP_REQUEST {
if { [HTTP::uri] equals "/www.mysite.com/" } {
HTTP::uri "/www.mysite.com/index.htm/"
}
}
They now want me to force the addition of www if the enduser does not enter it. How can I do this without getting www.www.mysite.com/index.htm/?
Sorry for a noob question, but I rarely am in this system.
5 Replies
- Deb_Allen_18Historic F5 AccountURL's take the form of:
scheme://host/uri
For this URL: http://www.mysite.com/index.htm
[HTTP::host] will return "www.mysite.com"
and
[HTTP::uri] will return "/index.htm"
If you just want to change the Host header to www.mysite.com and explicitly include the page name in the URI, you can use this code:
HTHwhen HTTP_REQUEST { if {[string tolower [HTTP::host] equals "mysite.com" } { HTTP::header replace Host "www.mysite.com" HTTP::uri "/index.htm" } }
/deb - Deb_Allen_18Historic F5 AccountActually, this makes more sense for the URI replacement:
when HTTP_REQUEST { if {[string tolower [HTTP::host] equals "mysite.com" } { HTTP::header replace Host "www.mysite.com" } if {[string length [HTTP::uri]] <= 1 } { HTTP::uri "/index.htm" } } - unRuleY_95363Historic F5 AccountI think he may actually want a redirect, so the users browser actually get's updated to include the www.
- Eric_Grepps_264
Nimbostratus
I am stumbling with the same issue. I need to add "www" only if the person did not enter it as the host.
I am starting with the following iRule.when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { HTTP::redirect https://[HTTP::host]/login.do } else { HTTP::redirect https://[HTTP::host][HTTP::uri] } }
I am using the above rule as a generic redirect across 20 or so domain names. I only need to place the www in front if the HTTP::host only contains a root domain name.
For example I need the following to occur:
http://domain.com --> https://www.domain.com
http://host1.domain.com --> https://host1.domain.com
http://host5.site1.domain.com --> https://host5.site1.domain.com
Any help would be greatly appreciated. - Eric_Grepps_264
Nimbostratus
I got it to work using the following iRule:when HTTP_REQUEST { set sHost "[getfield [string tolower [HTTP::host]] "." 3]" if { [HTTP::host] starts_with "www" }{ HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] } elseif {[string length $sHost] == 0 }{ HTTP::redirect https://www.[getfield [HTTP::host] ":" 1][HTTP::uri] } else { HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri] } }
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
