8

I am running an ASP.NET 4.0 website using IIS7 on Windows Server 2008 R2.

The site has a number of Web Applications under the main domain (~/site1, ~/site2, ~/site3, etc...). Each Web Application is an instance of the same website source folder (D:\Websites\MySite), so you can access the same website at any of the following URLs:

www.mydomain.com

www.mydomain.com/site1

www.mydomain.com/site2

www.mydomain.com/site3

The same website is returned each time, but with slightly different content depending on which specific URL is called.

Everything has been working fine for months until I was asked to add some SEO optimizations using URL Rewrite. Every URL Rewrite rule I add produces the following error:

HTTP Error 500.52 - URL Rewrite Module Error. The page cannot be displayed because an internal server error has occurred.

Config Error: Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'AddTrailingSlashRule1'

I have read elswhere that surrounding the <system.webServer> configSection in the web.config file with:

<location path="." inheritInChildApplications="false">

will fix this problem.

However, while it stops the error message from appearing, it also stops the URL Rewrite rules from working in any of the Web Applications (~/site1, ~/site2, ~/site3).

How can I get the URL Rewrite module to work with Web Applications?

Thanks for any help you can offer.

1 Answer 1

26

Add a clear to prevent the duplicate errors on subsites.

 <rules>
    <clear />
    <rule name="Redirect rule for /maps">
      ....
    </rule>
 </rules>
Sign up to request clarification or add additional context in comments.

4 Comments

This was really useful in dealing with a duplicate key issue for re-write rules inside of an Azure Web App. Many thanks!
Thank you so much @Dave Wiebelhaus. This is quite useful
Fixed my Laravel issue. Awesome
May I know where to add the <clear /> in applicationhost.config?

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.