'URL rewriting with /!#/ symbol in web.config

I want to redirect my old url https://mysite1.com/#!/page1 to new url https://mysite2.com/page1, other answers did not help, tried.

                <rule name="Red1" stopProcessing="true">
                    <match url="^([0-9]+)/page1" />
                    <action type="Redirect" url="https://mysite2.com" />
                </rule>


Solution 1:[1]

Assuming you meant #! per your example URL, not !# as in your title, add this JS to all your pages' <head>s:

(function(l,p){l.pathname==='/'&&(p=l.hash.match(/^#!(\/.*)/))&&l.replace(l.protocol+'//'+l.host+p[1])})(location);

This basically just removes the first /#!. You may have to alter it if your URLs contain a query part before the fragment.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Walf