It's possible to create a rewrite rule matching domain URL without a plugin

I’ve been looking for a solution where I ca rewrite a URL based on domain URL. So far the only way it seems is creating a middleware where check the domain and create a variable you can use later in the rewrite URL for all the paths. But I’d like to know if you can match directly against the domain URL (maybe on a trigger using request_context_matches?)

1 Like

Hi @Leobel_Izquierdo, welcome to the community.

Are you interested in getting the domain name / host or the full path (including the domain name)?

If it is the hostname then you could get it from the host header.

Hi, thanks for the reply. I don’t want just to “consume” the domain name (I mean using it in the rewrite_to), I wan to match it as we can do with the path, payload, query and headers. I though maybe using the request_context_matches but I can’t an example of using the domain name or the full URL in the regex.

For example I’d like to write two triggers, one when the URL has this pattern http://.+-testnet-.+\.com/(.+) (so the domain has testnet on it) and other with: http://.+-mainnet-.+\.com/(.+).