0

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?

0

1 Answer 1

0

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>
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for your answer. I tried your suggested match expression but it's not working either.
Are you sure it's not because of caching then? I tried the rule and it works. Try requesting your URL from the command line and/or disable the cache.
I tried requesting my URL from command line using curl -Ls -I - w %{url_effective} command to get the final url after redirect but it's still not working. I'm not sure what exactly causes the issue. Caching should be disabled.
Another thing to try is to match on (.*) and then specify the regex in a condition as shown in the examples here: blog.elmah.io/…. The reverse proxy example shows how to match on URL. You would not need the negate attribute in your case.
This actually did the trick. Thank you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.