diff --git a/src/backend/filters/urlRewrite.ts b/src/backend/filters/urlRewrite.ts
index 2a9b225..a884aeb 100644
--- a/src/backend/filters/urlRewrite.ts
+++ b/src/backend/filters/urlRewrite.ts
@@ -12,6 +12,14 @@ export default class URLRewriteFilter implements ContentFilter {
let html = await response.text();
const $ = cheerio.load(html);
+
+ // Insert or adjust the tag
+ if ($("base").length) {
+ $("base").attr("href", "/browse/");
+ } else {
+ $("head").prepend('');
+ }
+
["a", "link", "script", "img"].forEach((tag) => {
$.root()
.find(tag)
@@ -20,16 +28,7 @@ export default class URLRewriteFilter implements ContentFilter {
let urlValue = $(element).attr(attrName);
if (urlValue) {
if (!isICANN(urlValue)) {
- if (
- urlValue.startsWith("/") ||
- urlValue.startsWith("../") ||
- urlValue.startsWith("http")
- ) {
- console.log("before", urlValue);
- if (!urlValue.startsWith("/")) {
- urlValue = `/${urlValue}`;
- }
- console.log("after", urlValue);
+ if (urlValue.startsWith("http")) {
$(element).attr(attrName, `/browse${urlValue}`);
}
}