Need an iRule to append domain.com on an HTTPS request

I have an iRule set up to check my http requests

when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { *.domain.com { HTTP::redirect https://[HTTP::host][HTTP::uri] } default { HTTP::redirect https://[HTTP::host].domain.com[HTTP::uri] } } }

This is working great for http requests. So if someone enters any of the following in the browser it sends them to https://website.domain.com http://website.domain.com https://website.domain.com

The problem I have is if someone enters they get an error. I need to add the .domain.com on the end so it goes to https://website.domain.com.

Any ideas? I need this to be generic so it adds the .domain.com for any host (not just a specific website) as I will need to use this iRule for potentially dozens of sites.

Are the requests coming from the internet or the intranet? The problem I would see with this idea from the internet is that you have to have a fully qualified domain to being with (e.g. example.com) so you’d be trying to redirect to

example.com.domain.com

which I’m guessing isn’t what you want. So that would probably not work right.

Internally, if you’re just trying to redirect from a simple hostname to a fully qualified hostname (e.g.

https://example

to

https://example.domain.com

), you would need to create a new iRule a little different than your current one and then attach it to your HTTPS vip. something like this probably.

when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::host]] {
        *.domain.com {
             Do nothing
        }
        default {
            HTTP::redirect https://[HTTP::host].domain.com[HTTP::uri]
        }
    }
}