0

I'm working with URL rewriting in a Web.config file and I'm facing an issue with an extra slash appearing in my redirected URLs. Here’s the rule I've got so far:

<rule name="Redirect Users to Candidates" stopProcessing="true"> <match url="^users(.*)" /> <action type="Redirect" url="candidates{R:1}" /> </rule>

This rule is intended to redirect URLs in two scenarios:

When navigating to /users?text=smith, it redirects to /candidates/?text=smith. However, I want it to redirect to /candidates?text=smith without the additional slash before the query string.

It is also intended to redirect /users/A123456 to /candidates/A123456, which it does successfully, but I cannot get it to not have the additional trailing slash when there is a query string involved.

Thank you in advance!

2
  • Maybe share your entire rule config. It sounds like you have two rules at least, so maybe hey are interfering with each other. Commented Aug 20 at 4:35
  • simple test, Based on the rewrite rules you provided, I test and it works fine. Please provide the complete code for section <rewrite> in Web.config. Commented Aug 20 at 8:58

1 Answer 1

1

We fixed it with the addition of appendQueryString="true" as shown below.

<rule name="Redirect Users to Candidates" stopProcessing="true"> 
  <match url="^users(.*)" /> 
  <action type="Redirect" url="candidates{R:1}" appendQueryString="true" /> 
</rule>

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