Simpe, just want to rewrite the url from http://example.bleh.com to http://example.bleh.com/example.
I am doing the following, it simply doesn’t work and i can’t get any logging to output so i’m just sitting here flying blind. I’ve searched and searched and everybody keeps using static examples, which is a bad practice.
when RULE_INIT {
set ::domain ".bleh.com"
}
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
if { [string tolower [HTTP::host]] contains $::domain }{
set subdomain [getfield [HTTP::host] $::domain 1]
if { not ($subdomain == "") }{
set context [getfield $subdomain "-" 1]
HTTP::uri "$context"
}
}
}
}
I might be wrong, but your first example and your rule does not seem to match?
It has not been tested, but this rule should turn http://example.bleh.com to http://example.bleh.com/example.
when RULE_INIT {
set static::domain ".jbhunt.com"
}
when HTTP_REQUEST {
if { [HTTP::uri] equals "/" } {
if { [[HTTP::host] contains $static::domain }{
Get the first field of the host split by "."
set subdomain [getfield [HTTP::host] "." 1]
Change the uri
HTTP::uri "/$subdomain"
}
}
}
Two tips:
- Static is good practice for variables that’s not going to change.
- The host header comes in lower case, so there’s no need to actually use string to lower.
- I did not see a reason to validate “” against the subdomain variable since you are checking if the host contains “.jbhunt.com”. That would would validate that there is a sub domain, right?
/Patrik