Score:2

Remove hashmark (#) from nginx url and redirect

in flag

I want to take a url, add a prefix as well as remove the hashmark from the url. For example, redirect from http://localhost:8088/app1/#/hello to http://localhost:8088/apps/app1/hello.

I've tried this but it doesn't seem to work:

  location /app1/ {
    rewrite ^([^#]*)([#])\/(.*) /apps$1$3 permanent;
  }

It seems to have something to do with the hashmark. As I can go from http://localhost:8088/app1/q/hello to http://localhost:8088/apps/app1/hello with this:

  location /app1/ {
    rewrite ^([^q]*)([q])\/(.*) /apps$1$3 permanent;
  }

Is there something I need to do to handle the hashmark in a redirect?

vidarlo avatar
ar flag
[You can't](https://stackoverflow.com/questions/3664257/why-is-the-hash-part-of-the-url-not-available-on-the-server-side). It's never sent to the server.
Score:10
jp flag

You can't. The browser doesn't send anything after # to the nginx. The # indicates an URL fragment which is processed on a client only.

in flag
...and to be clear, as a consequence, the route handling for fragments need to happen in your http://localhost:8088/app1/ javascript code. That's a subject for stackoverflow, rather than serverfault though: https://stackoverflow.com/search?q=js+router
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.