Many projects are being migrated from AngularJS to Angular 2+. While doing such a migration, I had to make sure that links to the older AngularJS app are correctly redirected / rewritten to the new structure of the Angular 10 app.
So I needed to redirect URLs like:
http://example.com/oldapp/#/createTeams
to a new:
http://example.com/newapp/teams/create
The URLs for both apps had a base start, oldapp
and newapp
are not the actual ones, I'm using them here just as examples.
As we were using IIS to host our apps, the first idea was to do the rewriting in IIS, as rewrite rules in web.config using the URL Rewriter module.
The problem with that is that everything in the URL after the hash (#), the fragment, is not sent to the server, so from http://example.com/oldapp/#/createTeams
the server sees only http://example.com/oldapp/
, thus you can't access the rest of the URL to do the proper URL rewriting.