Reputation: 4635
I'm trying to use the IIS 7 URL Rewrite feature for the first time, and I'm having trouble getting my regular expression working. It seems like it should be simple enough. All I need to do is rewrite a URL like this:
http://localhost/myApplication/MySpecialFolder
To:
http://localhost/MySpecialFolder
Is this possible? I want the regular expression to ignore everything before "myApplication" in the original URL, so that I could use "http://localhost" OR "http://mysite", etc.
Here's what I've got so far:
^myApplication/MySpecialFolder$
But using the "Test Pattern..." feature in IIS, it says my patterns don't match unless I supply "myApplication/MySpecialFolder" exactly. Does anyone know how I can update my regular expression so that everything prior to "myApplication" is ignored and the following URLs will be seen as a match?
http://localhost/myApplication/MySpecialFolder
http://mysite/myApplication/MySpecialFolder
Many thanks in advance!
SOLUTION:
I needed to change my regex to:
myApplication/MySpecialFolder
Without the ^
at the beginning and without the $
at the end.
Upvotes: 1
Views: 2910
Reputation: 3279
Your regular expression is correct, the pattern will be matched against path starting after the first slash after the domain.
So only bold part will be used for matching: http://localhost/
myApplication/MySpecialFolder
To limit the rewriting to specific domain you have to use Conditions
section with Condition input
= {HTTP_HOST}
Upvotes: 2
Reputation: 732
Unless there is something radically different with regexes in IIS, you would want to take out the anchor (^
) at the beginning to match.
myApplication/MySpecialFolder$
The carat ^
tells it that that is the beginning of the string and the dollar sign $
tells it to match the end. A regex like abc
finds "abc" anywhere in the string, ^abc
matches strings that start with "abc", abc$
matches strings that end with "abc", and ^abc$
only matches when the whole string is "abc".
Upvotes: 1