static url rewrite, using rewrite map is not working

594 Views Asked by At

I have a website on azure, and I am trying to make some user-friendly urls to my websites use.

I have downloaded IIS remote manager, and did as it was explained here. Although the article is since 2008, the GUI of the remote IIS manager is still almost the same.

after defining the rewrite map, and the rule that looks inside the map, this is the web.config that was generated:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rewriteMaps>
                <rewriteMap name="StaticRewrites">
                    <add key="/niceurlpart" value="/Menu/master/#/Menu?Token=7926983e-c64e-4547-85f5-d85e3c06c7a8" />
                </rewriteMap>
            </rewriteMaps>
            <rules>
                <rule name="Rewrite rule1 for StaticRewrites" patternSyntax="ExactMatch">
                    <match url=".*" />
                    <conditions>
                        <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
                    </conditions>
                    <action type="Rewrite" url="{C:1}" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

when I enter inside the address bar: mydomain.com/niceurlpart I get: "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

Also, when I try to test the pattern inside the remote IIS manager, it fails..

am I missing something?

1

There are 1 best solutions below

6
On

Not sure on the syntax of doing this in web.config, but the # part of a URL doesn't reach the server, so using that in your rule won't work.

If you are using angular type app and are using # for routing, then try using HTML5 mode which will get rid of the hash.

If your are after SEO, you can google '_escaped_fragment_' to get the hash value to your server. Also if SEO is your goal then we use _escaped_fragment_, along with this tool https://prerender.io