Rewrite help, please

I used to have a single index page, with anchor links to notes, like https://example.com/#1234567. I have since changed the site to paginate that index, hence those links have broken. What it used to be https://example.com/#1234567 is now https://example.com/1234567.

How could I implement a rewrite that will strip that # from requests? Running Caddy v2.4.6. Thank you!

I have tried:

rewrite /# /

And (using the exact string):

rewrite /#1666614230 /1666614230

But doesn’t work.

Hmm, I am reading that the # part is never sent to the server, it is client side. I am leaning to believe this is not possible at all. Would love to hear from someone more versed than me, though. :sweat_smile:

I remediated this with JavaScript (gasp!). I didn’t see any other way to do it. For those that might be in the same situation as I was, this is the one liner I used:

<script> const wl = window.location; if (wl.hash) wl.href = wl.href.replace('#','') </script>

Not related to Caddy at all, I know, but it all started with me foolishly thinking it could be done with a server side rewrite.

1 Like

Correct. The “fragment” part of the URL is client-side only.

Please upgrade to the latest version, you should not be running versions that old! Latest is v2.6.4.

1 Like

I am running the beta now. :slight_smile: Thanks!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.