Creating the Worker Service
1. Open Workers Dashboard

2. Create a Service

You can name this whatever you want

3. Edit your worker

4. Add the following code

Please make sure to change the domain to your blog domain in line 16 as shown in the above screenshot.
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const urlObject = new URL(request.url)
if (urlObject.pathname.endsWith('/') && urlObject.pathname !== '/') {
urlObject.pathname = urlObject.pathname.slice(0, -1)
return Response.redirect(urlObject.toString(), 301)
}
const host = urlObject.host
try {
const blogHost = "my-blog.feather.blog"
const paths = ["blog", "_feather"]
let url = new URL(request.url)
const prevUrl = new URL(url)
if (
paths.some((path) => urlObject.pathname === `/${path}` ||
urlObject.pathname.startsWith(`/${path}/`))
) {
url.hostname = blogHost
}
let proxyRequest = new Request(url.toString(), request)
proxyRequest.headers.set("X-Forwarded-Host", host)
return fetch(proxyRequest)
} catch (e) {
return await fetch(request);
}
}
After adding the above code, click on “Save and Deploy”.
5. Go to Triggers and add the worker routes

We need two routes:
- /blog*
- /_feather*
For example, if you are trying to set up a subdirectory blog for feather.so domain, you would select the feather.so zone and add the required routes as shown in the below screenshots.


6. Setup Subdirectory in Feather dashboard
Go to Settings > Database Settings and then set the URL Prefix of all the things to blog.
