is there a way to filter access only to the domain root like www.mysite.com, and allow everything else, in order to allow users bookmarks and uri with specific url+uri
my irule is :
when HTTP_REQUEST {
if { ( [string tolower [HTTP::header Host]] equals “www.mysite.com” ) }{
log “client: [IP::client_addr], requested [HTTP::host][HTTP::uri]”
discard
}
}
i want to add the http::uri
thanks
Check this out
when HTTP_REQUEST {
if { NOT ( [string tolower [HTTP::host]] equals "www.mysite.com" ) } {
log local0. "client: [IP::client_addr], requested [HTTP::host][HTTP::uri]"
discard
}
}
The logic here is anything NOT matching www.mysite.com is discarded
Hope this helps
/CB
does your change will allow www.mysite.com/images/abc.jpg or some other uri ?
the meaning for this irule is to disallow the www.mysite.com/ and allow all other requests with specific uri
thanks
yes it will allow everything starting with www.mysite.com
because here we talk about the host and not the URI.
when you do www.mysite.com, www.mysite.com/abc/test.html
they have the same host which is www.mysite.com
If you need to allow some URI you’ll need to make some URI checking with the command [HTTP::uri]
The rule is to allow ONLY host “www.mysite.com” in with any combination of URI.
The NOT in the statement is simply to say the following:
“If hostheader is not www.mysite.com then block the request”
/CB
lets say i would like to redirect everything that goes to www.mysite.com, and different uri will not be redirected like: www.mysite.com/images/abc.jpg or any other request beside the www.mysite.com, do you have idea how to perform this ?
thanks
when HTTP_REQUEST {
if { [string tolower [HTTP::host] equals “www.mysite.com” } {
if { NOT ([HTTP::uri] contains “images”)} {
HTTP::redirect “www.newsite.com”
}
}
}
Here we redirect all users requesting www.mysite.com but not user where the uri contains images.
when HTTP_REQUEST {
if { [string tolower [HTTP::host] equals “www.mysite.com” } {
switch -glob [HTTP::uri] {
“/images*” -
“/admin*” -
default {
HTTP::redirect “www.newsite.com”
}
}
}
Here is another adding a discard into nmenant’s code
when HTTP_REQUEST {
if { [string tolower [HTTP::host] equals "www.mysite.com" } {
switch -glob [HTTP::uri] {
"/images*" -
"/admin*" -
default {
HTTP::redirect "www.newsite.com"
}
} else {
discard
}
}
im getting error on line1 and 2 ?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.mysite.com" } {
switch -glob [HTTP::uri] {
"/images*" -
"/admin*" -
default {
HTTP::redirect "www.newsite.com"
}
} else {
discard
}
}
1 ] was missing after the [HTTP::host]
If you can copy the error messages it may help too but should be ok now
i add the ], but it did’nt help then.
message :
line 1: [parse error: missing close-brace] [{
line 2: [command is not valid in the current scope] [if { [string tolower [HTTP::host]] equals “www.mysite.com” } {
Yes it it this :
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "www.mysite.com" } {
switch -glob [HTTP::uri] {
"/images*" -
"/admin*" -
default {
HTTP::redirect "www.newsite.com"
}
}
} else {
discard
}
}
1 } was missing to close the if statement sorry
thanks for your help, eventually i used this irule:
when HTTP_REQUEST {
if { [HTTP::uri] equals “/” } {
HTTP::redirect "http://site.mysite.com "
}
else {
pool newpool
}
}
my question is, if i can add another equals on the if line and use the “or” command ?
thanks
You sure can
Here is an example
when HTTP_REQUEST {
if { ([HTTP::uri] equals "/") or ([HTTP::uri] equals "/something") } {
HTTP::redirect "http://site.mysite.com "
}
else {
pool newpool
}
}
/CB