2

I am facing an issue where my URL is redirecting to Azure default domain instead of custom URL. I want to remove the trailing slash and make the URL in lowercase. For example: https://www.abc.com/About-Us/ should redirect to https://www.abc.com/about-us but in my scenario it redirecting to https://abc.azurewebsites.net/about-us

Rules Added are:

<rule name="RemoveTrailingSlashRule" stopProcessing="true">
   <match url="(.*)/$" />
   <conditions>
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
   </conditions>
   <action type="Redirect" url="{R:1}" />
  </rule>
  <rule name="Lowercase" stopProcessing="true">
     <match url="[A-Z]" ignorecase="false" />
     <action type="Redirect" url="{ToLower:{URL}}" />
  </rule>

I have also tried using {HTTP_HOST} but it did not work as well.

4 Answers 4

0

The rule you have added for remove trailing slash seems to be fine. But for transforming the string to lowercase can you add below rule.

<rule name="Convert to lower case" stopProcessing="true">
  <match url="^([^?]*[A-Z][^?]*)(\?.*)?" ignoreCase="false" />
  <action type="Redirect" url="https://www.abc.com/{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
</rule>

The root cause for this redirection from https://www.abc.com to https://abc.azurewebsites.net seems to be happening from Azure frontdoor or through some application gateway setup in front of your website. You can check for the redirection rules set up on them.

Update:

The redirection from https://www.abc.com to https://abc.azurewebsites.net might be prevented by configuring Application Gateway and App Service to not override the hostname under HTTP Setting. This settings instructs Application Gateway to access the App Service backend using the custom domain name.

You can check below link for getting additional details on the solution:

https://learn.microsoft.com/en-us/azure/application-gateway/troubleshoot-app-service-redirection-app-service-url

Hope this helps!!! Let me know in case you face any issues

2

Apparently you have some proxy in front of your website.

When a request hits your website, it's not pointing to www.abc.com hostname anymore, but to abc.azurewebsites.net.

Add target host name in <action>:

<action type="Redirect" url="https://www.abc.com/{R:1}" />

This will make sure that your requests are not redirected to azure domain.

0
1

You can use the transform to add the rewrite rule to read the HTTP_X_ORIGINAL_HOST server variable (which contains the value of the X-Original-Host header) and set its value to be the value of the HTTP_HOST variable.

<rewrite>
  <rules>
    <rule name="Set value of HTTP_HOST to value of X-ORIGINAL-HOST header" xdt:Transform="InsertIfMissing">
      <match url="(.*)"></match>
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_X_ORIGINAL_HOST}" pattern="^$" negate="true" />
      </conditions>
      <serverVariables>
        <set name="HTTP_HOST" value="{HTTP_X_ORIGINAL_HOST}"></set>
      </serverVariables>
    </rule>
  </rules>
<rewrite>

For more reference follow this article.

Hope this helps.

2
  • Thank you, It worked for me Commented Sep 3 at 12:22
  • @AniketBajpai If the solution works for you kindly accept the answer for other people to find it useful. Thanks Commented Sep 3 at 12:26
0

It looks like your URL is getting redirected to the Azure default domain due to the rules you've set up. Let's address the issues step-by-step and update your URL rewrite rules to ensure that they handle the trailing slash removal and lowercase conversion correctly, and to make sure that requests are not redirected to the Azure default domain.

Steps to Fix the URL Redirection Issue

1.Ensure Custom Domain is Correctly Set Up: Make sure that your custom domain is properly configured in Azure. Verify that your custom domain is set up in the Azure portal and is correctly mapped to your Azure Web App.

2.Update URL Rewrite Rules: The rules you provided have a couple of issues that need to be corrected:

The Lowercase rule should be applied before the RemoveTrailingSlashRule. Use proper syntax for the ToLower transformation.

Here’s a revised version of your rewrite rules:

<rules>
  <!-- Convert URL to lowercase -->
  <rule name="Lowercase" stopProcessing="true">
    <match url="[A-Z]" ignoreCase="false" />
    <action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
  </rule>

  <!-- Remove trailing slash -->
  <rule name="RemoveTrailingSlashRule" stopProcessing="true">
    <match url="(.*)/$" />
    <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    </conditions>
    <action type="Redirect" url="{R:1}" redirectType="Permanent" />
  </rule>
</rules>

By applying these updated rules and checking your domain configuration, you should be able to resolve the issue with URL redirection and ensure that the URLs are properly transformed.

1
  • Not working, I have tried adding the custom rule mentioned. I have checked the custom domain as well. Commented Sep 2 at 10:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.