Hello, I want to change the blogger permalink /p/test.html to /test-page/ and also canonical link and other links. but still can't rewrite the canonical and other links.
first code, with route settings like this: www.domain.com/test-page*
I'm not entirely sure. I don't think I've ever tried to change canonical links with Cloudflare workers. They have lots of examples in their docs though. You should be able to modify one of those examples to suit your needs.
when I just run the code rewrite it works rewrite the canonical link with route www.domain.com/p/test.html. I can't seem to run concurrently, is there maybe something wrong with my route settings? I've also changed my codes and still the same still can't rewrite the canonical link.
Adi
Hello, I want to change the blogger permalink /p/test.html to /test-page/ and also canonical link and other links. but still can't rewrite the canonical and other links.
first code, with route settings like this:
www.domain.com/test-page*addEventListener("fetch", event => { return event.respondWith(fetch("domain.com/p/test.html")) })the second code, and the route settings are like this
*.domain.com/test-page*const OLD_URL = "domain.com/p/test.html"; const NEW_URL = "domain.com/test-page"; async function handleRequest(req) { const res = await fetch(req) return rewriter.transform(res) } class AttributeRewriter { constructor(attributeName) { this.attributeName = attributeName } element(element) { const attribute = element.getAttribute(this.attributeName) if (attribute) { element.setAttribute( this.attributeName, attribute.replace(OLD_URL, NEW_URL) ) } } } const rewriter = new HTMLRewriter() .on("link", new AttributeRewriter("href")) .on("meta", new AttributeRewriter("content")) addEventListener("fetch", event => { let url = event.request.url event.respondWith(handleRequest(url) .catch(err => new Response(err.toString(),{status:500}))) })