0

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.

rhellem
  • 295
  • 1
  • 5
  • 14

1 Answers1

1

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.

HBruijn
  • 77,029
  • 24
  • 135
  • 201