https matching

Hi,

I have an issue where we are re-directing http > https and adding some extra lines to a URI on the port re-direct.

When we target the Virtual server directly on HTTPS the re-direct is missed, and we just see the Admin page.. so ther serverside is not capible of the re-direct without the extended URI.

I need a solution in the HTTPS virtual server to match the Hostnames and ensure that they have the extra URI string to hit the web server directly.

so https://mysite.com/something/something

thanks

do you mean to rewrite uri when sending to server? if yes, you may check HTTP::uri command.

HTTP::uri

Not sure if that is what I need..

The https request needs to match against the hostname and if nothing is typed after the end of that.

so a url /

the server responds with a redirect to another site.. so its a re-direct to that location that the client receives.

Not sure if that is what I need..

it may be easier to understand if you can give some example what you are looking for.

ok..

so if you type http://mysite.com then you are redirected from http > https and a URI is added:

so the client is now https://mysite.com/something

the issue is.. if you just type https://mysite.com you are not redircted and you dont hit the /something site that produces the server re-direct that makes it work.. you just hi the default server admin page.. which is wrong.

what i need is to match if nothing is typed into the browser after mysite.com and force a redirect with the /something added on for that condition.

I think you are looking for a basic modification of the _sys_https_redirect iRule from:

when HTTP_REQUEST {
   HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}

To something like:

when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] equals "/" } {
   HTTP::redirect https://[getfield [HTTP::host] ":" 1]/something/something
} else {
   HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}

the issue is.. if you just type https://mysite.com you are not redircted and you dont hit the /something site that produces the server re-direct that makes it work.. you just hi the default server admin page.. which is wrong.

are you using irule to redirect from http://mysite.com to https://mysite.com/something? if yes, have you assigned the irule (which is being used by http virtual server) to https virtual server?

the issue is.. if you just type https://mysite.com you are not redircted and you dont hit the /something site that produces the server re-direct that makes it work.. you just hi the default server admin page.. which is wrong.

are you using irule to redirect from http://mysite.com to https://mysite.com/something? if yes, have you assigned the irule (which is being used by http virtual server) to https virtual server?

no i have not … but i guess it could re-direct in a loop without the matching condition.. as some of the requests are correct ??

no i have not … but i guess it could re-direct in a loop without the matching condition.. as some of the requests are correct ??

but i guess it could re-direct in a loop without the matching condition.. as some of the requests are correct ??

yes, you have to check uri before redirect similar to the one Brain suggested.

this is just another example.

e.g.

[root@ve11c:Active:In Sync] config  tmsh list ltm virtual bar443
ltm virtual bar443 {
    destination 172.28.24.10:443
    ip-protocol tcp
    mask 255.255.255.255
    pool foo
    profiles {
        clientssl {
            context clientside
        }
        http { }
        tcp { }
    }
    rules {
        qux
    }
    source 0.0.0.0/0
    source-address-translation {
        type automap
    }
    vs-index 13
}
[root@ve11c:Active:In Sync] config  tmsh list ltm rule qux
ltm rule qux {
    when HTTP_REQUEST {
  if { [HTTP::uri] equals "/" } {
    HTTP::redirect "https://[HTTP::host]/something"
  }
}
}

[root@ve11c:Active:In Sync] config  curl -Ik https://172.28.24.10
HTTP/1.0 302 Found
Location: https://172.28.24.10/something
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

How does this look ? match http request if you only have the hostname so “/” would redirect to Https with the /something/something

if you already have the /something/something you drop to the default pool.

this would be applied to the Https Virtual Server

when HTTP_REQUEST { switch -glob -- [string tolower [HTTP::uri]] { “/” { HTTP::redirect https://[getfield [HTTP::host] “:” 1]/something/something return } “/something/something/*” default { pool mysite-pool } } }

yours is more elegant i think.. [HTTP::uri]

when HTTP_REQUEST { if { [HTTP::uri] equals “/” } { HTTP::redirect “https://[HTTP::host]/something” } }

i think you do not need /something/something/* pattern because it will match default pattern anyway.

when HTTP_REQUEST { 
  switch -- [string tolower [HTTP::uri]] { 
    "/" { 
      HTTP::redirect "https://[getfield [HTTP::host] ":" 1]/something/something"
      return 
    } 
    default { 
      pool mysite-pool
    } 
  } 
}

Just a quick one.

if I use this, when I come in with something/something already in the URI I presume it wont match and ignore the Irule

when HTTP_REQUEST { if { [HTTP::uri] equals “/” } { HTTP::redirect “https://[HTTP::host]/something” } }

yes, it doesn’t match if expression (because uri is not equal to /) and, of course, body (HTTP::redirect) won’t be executed.

I put this irule into the https virtual server but it has no impact whatsoever..

I would use this as an irule for a https server:

when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] equals "/" } {
    HTTP::redirect https://[getfield [HTTP::host] ":" 1]/something/something
    }

can you do some debugging? https://devcentral.f5.com/s/articles/getting-started-with-irules-logging-comments-20406

ok so its working for some browers not for Mozilla ??

really dont know why.. its very strange.. any ideas why Firefox would ignore the rule..??

when HTTP_REQUEST { if { [HTTP::uri] equals “/” } { HTTP::redirect “https://[HTTP::host]/something/something” } }