Avatar of mike99c
mike99c
 asked on

URL rewrite to only match on top level folder

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.
Microsoft IIS Web ServerRegular Expressions

Avatar of undefined
Last Comment
NerdsOfTech

8/22/2022 - Mon
Dan McFadden

Try this:

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

Open in new window


Dan
mike99c

ASKER
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
ASKER CERTIFIED SOLUTION
NerdsOfTech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy