Add RemoveTrailingSlashRule to website hosted on Azure App Service

Vinay Kumar 21 Reputation points
2022-10-20T06:14:20.237+00:00

HI ,
I have MVC website hosted on Azure App service , I need add "Remove Trailing Slash Rule" so that it removes ".pdf" coming in the URL.
I tried putting below piece of config in web.config with no luck. Please suggest . Thanks

example rule :
<rewrite>
<rules>
<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
<match url="(.*)/.pdf" />
<conditions>
</conditions>
<action type="Redirect" url="{R:1}" />
</rule>
</rules>
</rewrite>

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,080 questions
0 comments No comments
{count} votes

Accepted answer
  1. VenkateshDodda-MSFT 14,216 Reputation points Microsoft Employee
    2022-10-20T07:31:33.923+00:00

    @Vinay Kumar Thank you reaching out to Microsoft Q&A. Apologize for the inconvenience caused any on this.

    Based on the shared information, we have understood that if the incoming request url of web app which ends with .pdf should be redirected to a different url. for that your regrex expression in the match condition should be in below format instead of above.

     <rewrite>  
      <rules>  
        <rule name="Rewrite to article.aspx">  
          <match url="^(.*)\.pdf" />  
          <action type="Redirect" url="{R:1}" />  
        </rule>  
      </rules>  
    </rewrite>  
    

    I have tested this from my end it is working fine and I would suggest you validate it from your end as well.
    Feel free to reach back to me if you have any further questions on this.


0 additional answers

Sort by: Most helpful