简体   繁体   中英

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 ? .

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM