What is the name of the domain?
What is the issue you’re encountering
subpage mapping issues
We need assistance in configuring our new domain and sites.
We have hosted a testing.com site and its A record is 1.2.3.4, now we need to point subpages to a different backend server IP address.
Example:
testing.com/page points to a backend server IP address of 1.3.3.4
testing.com/tools points to a backend server IP address of 1.5.5.4
In Cloudflare how can we configure to point the subpages to the backend server ip address?
Note: We prefer not to redirect to different domains. Instead, subpage content should be served from various backend IP addresses.
You could give each backend server a DNS record (say backend1
and backend2
), then you can use a Worker (or a Snippet if on a paid plan) to proxy the requests and steer them to the relevant backend hostname.
Yes, I have a business plan for the domain.
I am new to Cloudflare, is there any documentation or steps to configure in worker.
Use a Snippet then, as they are free.
Start with this simple example, then modify it to return from backend1.example.com
or backend2.example.com
depending on the path in the request…
The provided documentation for the sub-page did not work. Therefore, I made modifications to the snippet to access the subpages of backend1.example.com.
export default {
async fetch(request) {
// Base URL of the remote host
const remoteBase = “https://backend1.example.com”;
// Extract the entire path and query parameters from the incoming request
const url = new URL(request.url);
const fullPath = url.pathname + url.search; // This includes path and query parameters
// Construct the full remote URL
const remoteUrl = remoteBase + fullPath;
// Forward the request to the constructed remote URL
const response = await fetch(remoteUrl, request);
return response;
},
};
Now, when accessing testing.com/page/test, it will retrieve the HTML from backend1.example.com/test.
Since this is a beta version, can we also use the snippet in our production environment?
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.