Search code examples
azureurl-rewritingweb-config

URL Rewrite from web.config in Azure Application does not work


I want to redirect my users from "https://mywebsite.azurewebsites.net/Spa/de/#/.." to "https://mywebsite.azurewebsites.net/Spa/en/#/.." using url rewrite in web.config but it is not working. I stay on the "de" url.

The application is an angular web application deployed to azure.

I wrote the following rewrite rule in web.config but the redirect is not working as expected.

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Redirect from de to en" enabled="true" stopProcessing="true">
                <match url="(.*)/Spa/de/(.*)" />
                <action type="Redirect" url="{R:1}/Spa/en/{R:2}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

What am I missing?


Solution

  • I'm not entirely sure, but I think there's a problem with your match. I belive this works:

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect from de to en" enabled="true" stopProcessing="true">
                    <match url="^Spa/de/(.*)$" />
                    <action type="Redirect" url="/Spa/en/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>