Score:0

Apache - Is it possible to rewrite urls based on fragments (hashtag)?

cn flag

Using Apache/2.4.54 (Win64)

I have been requested to rewrite from old domain to new like this

  • From https://oldtest.mydomain.com/company/customerpage/#/customer/<getThisNumber>/something
  • To https://newtest.mydomain.com/company/something/customer/<getThisNumber>

It could have been fine, using regex to grab the number and pass it to the new and then just redirect using [L,R=301].

But ref. this post on StackOverFlow

I know the hashtag is a fragment identifier and that strings after the hashtag aren't something you can process with mod_rewrite, but I was expecting the hashtag itself to show up. So I've tried rules to match like these

So what I have tried is (snippet)

<LocationMatch "^\/company\/customerPage\/">
    LogLevel alert rewrite:trace3
    RewriteCond %{QUERY_STRING} ([0-9]*)\/something$
    RewriteRule ^(.*)$ "https://newtest.mydomain.com/company/something/customer/$1" [L,R=301]

This does not work, question is if I have a minor issue in my code or I am also aware that there might be a risk for this not being doable...but hopefully not.

Score:1
in flag

https://www.w3.org/Addressing/URL/4_URI_Recommentations.html

The hash (# , #, ASCII 23 hex) character is reserved as a delimiter to separate the URI of an object from a fragment identifier .

Implied there that means that

  • The # hashtag is NOT part of the URI.

  • And only the URI is sent to the web server.
    The hash and fragment identifier do NOT get sent to the web server in the request.

There is simply nothing serverside for Apache and/or mod_rewrite to process.


You would need to solve that by something that runs client side; like javascript fro example, that runs in the browser window.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.