Sharing the solution shared by @Shaun Chen with the community. Thanks for confirming and sharing the solution.
Scenario: WebApp hosted on an App Service. The application is configured to serve index.html
for all requests with unmatched paths, either returning a 200 (uncached) or 304 (cached) response. Virtual application with /test
as the path and \site\test
as the physical path.
Issue: When visiting the URL https://<appservice>/test/anypath
, the App Service returns a 301 redirect response to /test
. This behavior is different from the root application and prevents users from directly accessing sub-routes in a single-page application, forcing them to start from the entry route (i.e., /test
).
Things Tried:
- You have configured the
web.config
in the root directory (/site/wwwroot/web.config
) to serveindex.html
for all requests with unmatched paths. - You deleted
/site/wwwroot/web.config
because the virtual application would not work otherwise. - You added a virtual application with
/test
as the path and\site\test
as the physical path in the virtual application and directory. - You configured the
web.config
in the test directory (/site/test/web.config
) to rewrite URLs to/test
.
Answer shared by @Shaun Chen.
Resolution :
Modifying/add the trailing slash rewrite URL.
Referenced URLs:
- IIS URL rewrite is redirecting instead
- IIS generates courtesy redirect when folder without trailing slash is requested
Note: This response contains a reference to a third-party World Wide Web site. Microsoft is providing this information as a convenience to you.
If the answer helped (pointed you in the right direction) > please click Accept Answer - it will benefit the community to find the answers quickly.