URL rewrite to only match on top level folder

mike99c
mike99c used Ask the Experts™
on
I use windows 2008 server with IIS7 and have created the following URL rewrite rule:

<rule name="Rewrite english to /index.asp">
      <match url="english" />
      <action type="Rewrite" url="index.asp" />
 </rule>

Open in new window


What this does is when the URL is written as:

www.mywebsite.com/english

It would redirect to:

www.mywebsite.com/index.asp

The only problem is that if there are any files on the website which start with the text "english" then the rule would apply to that filename. I have an image called english-rose.jpg which would not display when this rule was in place. As soon as I removed the rule it was fine.

So what I want is to change the rule so it only matches on /english and no other variation.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dan McFaddenSystems Engineer

Commented:
Try this:

<rule name="Rewrite english to /index.asp">
      <match url="english/" />
      <action type="Rewrite" url="index.asp" />
 </rule>

Open in new window


Dan

Author

Commented:
Thanks Dan. While this has solved the issue of the image now being recognised, the problem I have now is that the URL only works with the forward slash in front like so:
www.mywebsite.com/english/

But I would still like it to work as before:
www.mywebsite.com/english
Technology Scientist
Commented:
try:
<match url="english(\/)?$">

Open in new window


MATCHES:
english/
english

BUT DOES NOT MATCH:
english-rose.jpg
english.php
english.html
english/1

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial