Continuing the discussion from Discourse rewriting url path behaviour failing due to subfolder:
I have the exact same issue from the aforementioned topic, in which the URL is rewritten only in scenarios where the start of a sub-route is equal to the subfolder. I’m using
/f as subfolder, I understand the caveats and pains of this setup, but everything else is working fine so I’d like to get some help fixing this, if possible.
I’m not using an existing Discourse route, but if the one-letter subfolder is an issue I’d like to try fixing it before considering a different setup.
Some routes that get rewritten:
As it’s a client-side rewrite, CURL’ing the same URLs works fine.
Following the calls to that
location.pathname is correct on first call (starting with
/f), but on one of the next calls the subfolder gets stripped and becomes
/t/f-started-slug/id, causing this replace to act on that
I don’t know enough of Discourse internals to fully understand where this rewrite is taking place, but testing in my instance, enforcing the replace in
withoutPrefix to only act at the beginning of
path seems to fix it.
// changing ... return path.replace(rootURL, ""); // to something like ... (assuming rootURL doesn't need to be escaped) return path.replace(new RegExp("^" + rootURL), "") // or without regex ... return path.indexOf(rootURL) === 0 ? path.slice(rootURL.length) : path;
I don’t know if that would be a possible fix or if it would introduce any regression, any help is appreciated.