I am using the try_files directive with nginx and react to force all paths to go to /index.html and be handled by the react router so that the paths don't need to be prefaced with /#/.
This works for that:
location / {
try_files $uri /index.html;
}
So a url like /invitation
will go to the right place.
However, there are still some sources that are generating /#/
urls and I would like to have them rewritten to the equivalent urls without the /#/
(so /#/invitation
would go to /invitation
).
I have tried every variation I can think of on this, including changing the order, escaping special characters, and with and without the permanent redirect, but nothing works:
location / {
rewrite ^/#/(.*) $1 permanent;
try_files $uri /index.html;
}
What's the right way to do this?