I have seen a thousand examples of this:
<rule name="ex1" enabled="false" stopProcessing="true">
<match url="^article/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="article/{R:1}.html" />
</rule>
Which I can easily get to work. What I am trying to do however is to have www.mydomain.net/test rewrite to www.mydomain.net/test.html which I tried to make work with the config below.
<rule name="ex2" enabled="true" stopProcessing="true">
<match url="^/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/{R:1}.html" />
</rule>
Unfortunately I haven´t had any success and I get a simple 404 on every try. Although, when I test my regex it is successful for anything that I wish to match - eg www.mydomain.net/test.
Can anybody provide any insight into why this is?
(Using Win7, IIS7 Ultimate).
You might try matching on this instead:
"^([^/]+)/?$"
And replacing with this:
{R:1}.html
I'm not certain, but I don't think IIS matches on the leading / so that might be what is tripping up your rewrite.
Example: http://regexr.com?36jiq
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.