1

I have a path of the format www.example.com/aaa and www.example.com/aaa#bbb and I want to redirect it to www.example.com

I tried:

if ($uri ~ ^/(.*)(#.*)?) {
    rewrite ^/(.*)(#.*)? / permanent;
}

I even tried #. It seems to go inside if block. It replaces the first part, but the second part is appended to url. The new url becomes like www.example.com/#bbb

Joaquin
  • 2,013
  • 3
  • 14
  • 26

1 Answers1

2

The hash in a URL (the portion of the URL following the #) is not sent in the HTTP request by design. Therefore, nginx can't do anything about it. When a user visits http://example.com/#aaa, nginx only sees a request for http://example.com

One potential workaround is to use Javascript on the front-end to remove the hash from the URL. Another Stack Overflow question describes how to do this: https://stackoverflow.com/a/4508751/3474615

Zach Bloomquist
  • 5,309
  • 29
  • 44