HTTPS redirects

Hello, I am a complete novice as far as f5 devices are concerned, and I need to achieve the following:

Any traffic to http://testssl.mydomainmail.co.uk gets redirected to mydomain.co.uk - mydomain Resources and Information.

Any traffic to http://testssl.mydomainmail.co.uk/anything gets redirected to mydomain.co.uk - mydomain Resources and Information. (where “anything” could be any URL)

Any traffic to mydomain.co.uk - mydomain Resources and Information. gets redirected to mydomain.co.uk - mydomain Resources and Information.

Any traffic to mydomain.co.uk - mydomain Resources and Information. gets redirected to mydomain.co.uk - mydomain Resources and Information. (where xxx can be anything)

So far I have this:

• Any traffic to http://testssl.mydomainmail.co.uk gets redirected to mydomain.co.uk - mydomain Resources and Information.

1 when HTTP_REQUEST { 2if{ [HTTP::host] contains “http://testssl.mydomainmail.co.uk”} {

3 HTTP::redirect mydomain.co.uk - mydomain Resources and Information. [HTTP::uri]

• Any traffic to mydomain.co.uk - mydomain Resources and Information. gets redirected to mydomain.co.uk - mydomain Resources and Information.

1 when HTTP_REQUEST { 2if{ [HTTP::host] contains “mydomain.co.uk - mydomain Resources and Information.”} {

3 HTTP::redirect mydomain.co.uk - mydomain Resources and Information. [HTTP::uri]

Any help would be appreciated.

e.g.

config

[root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
ltm rule qux {
    when HTTP_REQUEST {
  if { [HTTP::host] eq "testssl.mydomainmail.co.uk" } {
    switch [string tolower [HTTP::path]] {
      "/" {
        HTTP::redirect "https://testssl.mydomain.co.uk/login"
      }
      default {
        HTTP::redirect "https://testssl.mydomain.co.uk[HTTP::uri]"
      }
    }
  } elseif { [HTTP::host] eq "testssl.mydomain.co.uk" } {
    switch -glob [string tolower [HTTP::path]] {
      "/login" -
      "/???lz/*" {
        HTTP::redirect "https://testssl.mydomain.co.uk[HTTP::uri]"
      }
    }
  }
}
}

 test

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomainmail.co.uk
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/login
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomainmail.co.uk/anythingbhabhabha
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/anythingbhabhabha
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomain.co.uk/login
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/login
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomain.co.uk/123lz/anythingbhabhabha
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/123lz/anythingbhabhabha
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

e.g.

config

[root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
ltm rule qux {
    when HTTP_REQUEST {
  if { [HTTP::host] eq "testssl.mydomainmail.co.uk" } {
    switch [string tolower [HTTP::path]] {
      "/" {
        HTTP::redirect "https://testssl.mydomain.co.uk/login"
      }
      default {
        HTTP::redirect "https://testssl.mydomain.co.uk[HTTP::uri]"
      }
    }
  } elseif { [HTTP::host] eq "testssl.mydomain.co.uk" } {
    switch -glob [string tolower [HTTP::path]] {
      "/login" -
      "/???lz/*" {
        HTTP::redirect "https://testssl.mydomain.co.uk[HTTP::uri]"
      }
    }
  }
}
}

 test

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomainmail.co.uk
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/login
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomainmail.co.uk/anythingbhabhabha
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/anythingbhabhabha
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomain.co.uk/login
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/login
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

[root@ve11a:Active:In Sync] config  curl -I http://testssl.mydomain.co.uk/123lz/anythingbhabhabha
HTTP/1.0 302 Found
Location: https://testssl.mydomain.co.uk/123lz/anythingbhabhabha
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

Thanks very much for this, will test.

That worked partially: Any traffic to http://testssl.communigatormail.co.uk gets redirected to https://testssl.communigator.co.uk/login - Doesn’t work Any traffic to http://testssl.communigatormail.co.uk/anything gets redirected to https://testssl.communigator.co.uk/anything (where “anything” could be any URL) - Doesn’t work Any traffic to http://testssl.communigator.co.uk/login gets redirected to https://testssl.communigator.co.uk/login - Works Any traffic to http://testssl.communigator.co.uk/xxxlz/ anything gets redirected to https://testssl.communigator.co.uk/xxxlz/ anything (where xxx can be anything) - Works I’m wondering if switch -glob should be used in the earlier command?

That worked partially: Any traffic to http://testssl.communigatormail.co.uk gets redirected to https://testssl.communigator.co.uk/login - Doesn’t work Any traffic to http://testssl.communigatormail.co.uk/anything gets redirected to https://testssl.communigator.co.uk/anything (where “anything” could be any URL) - Doesn’t work Any traffic to http://testssl.communigator.co.uk/login gets redirected to https://testssl.communigator.co.uk/login - Works Any traffic to http://testssl.communigator.co.uk/xxxlz/ anything gets redirected to https://testssl.communigator.co.uk/xxxlz/ anything (where xxx can be anything) - Works I’m wondering if switch -glob should be used in the earlier command?

Because everything is getting redirected to the same HTTPS URL, you could probably simplify this by simply evaluating the URI.

when HTTP_REQUEST {
    if { [HTTP::uri] equals "/" } {
        HTTP::redirect "https://testssl.communigator.co.uk/login"
    } else {
        HTTP::redirect "https://testssl.communigator.co.uk[HTTP::uri]"
    }
}