logo

Thy Quill

Using Thy Quill with a subdirectory

If you have an existing site for example a shop, or a static site hosted elsewhere Thy Quill can be run from a separate location e.g. yourdomain.com/blog, otherwise known as a subdirectory.

Cloudflare

It's possible to setup a reverse proxy using Cloudflare Workers to establish a subdirectory on Thy Quill.


Use of Cloudflare Workers for a subdirectory setup is considered highly advanced and may require additional technical knowledge and troubleshooting.


Paste the exact configuration below into the Worker script area, updating each line as specified so that it meets our reverse proxy rules, and ensure that your setup references the subdirectory path you are wanting to use (e.g. /^\\/blog/).


Ex : "yourdomain.com/blog"

SUB_DIRECTORY : "blog"
CUSTOM_DOMAIN : "blog.yourdomain.com"

SUB_DOMAIN : "blog"

DOMAIN : "yourdomain"

TOP_LEVEL_DOMAIN: "com"


addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
const url = new URL(request.url);

if (url.pathname === "/SUB_DIRECTORY" || url.pathname.startsWith("/SUB_DIRECTORY/")) {
const proxiedUrl = new URL(request.url);
proxiedUrl.pathname = proxiedUrl.pathname.replace(/^\/SUB_DIRECTORY/, "");
proxiedUrl.hostname = "CUSTOM_DOMAIN";

const response = await fetch(proxiedUrl);

const contentType = response.headers.get("Content-Type");
if (contentType && contentType.includes("text/html")) {
let html = await response.text();

html = html.replace(/(href|src)=["']\/(?!SUB_DIRECTORY\/)(.*?)["']/g, `$1="/SUB_DIRECTORY/$2"`);
html = html.replace(/(href|src)=["']https?:\/\/SUB_DOMAIN_\.DOMAIN\.TOP_LEVEL_DOMAIN\/(.*?)["']/g, `$1="/SUB_DIRECTORY/$2"`);

return new Response(html, {
status: response.status,
headers: response.headers,
});
}

return response;
}

return fetch(request);
}

Authors

A

Akash