Learn how you can access your blog under a subdirectory of a custom domain you own
Updated: October 24, 2024
5 mins read
thinkingtypes.com/blog, you need to set up a reverse proxy of some sort. Settings → Domain Setup for the blog.
.stomod.com subdomain your blog is configured to be accessible via. In our case for this tutorial, we can see that the blog is accessible via https://testcloudflare.stomod.com.Custom Domain with Subdirectory from the Custom Domain Type and then in the subsequent fields, provide your domain and the folder under the domain where the blog will be accessible.thinkingtypes.com and the custom domain subdirectory is blog.Save Settings to save your changes.Workers & Pages → Overview and click on Create to create your new worker.

Deploy. In this instance, we are calling the worker blog-rewriter.
Edit Code on the next page.
targetHost variable is changed to the HTTPS url of your Stomod blog subdomain address.https://testcloudflare.stomod.comhttps:// is required so that the worker resolved using the right protocol.export default {
async fetch(request, env, ctx) {
// Parse the incoming request URL
const url = new URL(request.url);
// Replace this by your Stomod blog subdomain URL
const targetHost = 'https://testcloudflare.stomod.com';
// Create a new URL object with the target host and the original path and query
const targetUrl = new URL(url.pathname + url.search, targetHost);
// Forward the request to the target URL.
// You might want to clone the request to modify its headers for the target endpoint.
const init = {
method: request.method,
headers: request.headers,
// If the request method is not GET or HEAD, forward the body as well.
body: request.method === 'GET' || request.method === 'HEAD' ? undefined : request.body
};
// Make the fetch request to the target URL
const response = await fetch(targetUrl, init);
// Return the response from the target URL to the original requester
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: response.headers
});
},
};
Deploy to update the worker.
Settings page and under Domains & Routes, click on Add to add a new route which will trigger the worker.
Route to map a URL pattern to your worker as shown below:
thinkingtypes.com/blog* - take note of the * present at the end.
Domains & Routes as shown below:

routeRules to your nuxt.config.ts file:// nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/blog/**': { proxy: 'https://testcloudflare.stomod.com/**' },
},
});Was this resource helpful?