How to resolve to a specific ip depending on the url requested

Hi, how I can set an specific ip address depending on the url requested?

For example, we need:

Please note that we don’t want to forward request to another url responding to the user with some code like 301, we need to “resolve” the user request to a specific ip.

We have tried to create an A record setting “mysite.com/specific.php” as “Name”, however this is not possible.

Thanks!

Generally this is not possible. However you could achieve this with a custom Worker script, where you map only that particular path to your Worker and then handle all requests manually and forward them to the host in question. The search will have more on Worker scripts and how to set them up.

Keep in mind, Workers are paid if you exceed the free limit.

Hi, how I can set an specific ip address depending on the url requested?

For example, we need:

Please note that we don’t want to forward request to another url responding to the user with some code like 301, we need to “resolve” the user request to a specific ip.

We have tried to create an A record setting “mysite.com/specific.php” as “Name”, however this is not possible.

Thanks!

This is not possible due to how DNS works - a browser trying to go to example.com/one will first resolve example.com then send the URL request to the IP it got back. It doesn’t tell the DNS server what URL it’s requesting.

https://www.cloudflare.com/learning/dns/what-is-dns/

Your best bet would be to do something like this Not possible to override the Host header on Workers requests - #2 by KentonVarda

For a proxied record you can do this with a page rule (Resolve Override) if you are on an ENT plan, otherwise you can do it with workers.

^^^^ correct.

3 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.