Help in migrating from ISAPI_Rewrite to IIS7 URL Rewriting
I've this ISAPI_Rewrite rule:
RewriteRule /([^/.?]+) /sc.asp?p=$1 [I,L]
This rule should rewrite Urls like:
/some-article
/article2
and shouldn't rewrite Urls like:
/home.asp
/admin (because there's a directory named admin)
/admin/
/sites/gutterman
It works great in ISAPI_Rewrite Yesterday I bought a Windows 2008 R2 VPS, and I started to transfer my ASP-classic web application to the new server. Now, everything is working great, except for URL Rewriting. I google-ed a little bit and found that the IIS7 URL Rewrite module is completely different from the ISAPI_Rewrite.
I created a Blank Rule. In the pattern I set /([^/.?]+)
, in Action -> Action Type I set Rewrite
and in Action -> Action properties开发者_运维百科 -> Rewrite Url I set sc.asp?p={R:0}
. It didn't work.
After some googling I found that I have to remote the /
character in the start of my pattern (so my pattern is now ([^/.?]+)
). So I did it, and now, it is just rewriting any url, and it should rewrite only urls that aren't directories or files.
Any ideas?
Thank you.
The simplest way to avoid rewriting URLs that actually point to existing files is to add these conditions:
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
Also, your match pattern shows a common misconception. The querystring is not passed to the Match URL pattern, so you don't need to look for ?
.
精彩评论