简体   繁体   中英

IIS 7 URL Redirect based on URL path

I have a WCF Web Service hosted inside a ASP.NET 4 environment (IIS 7.5 on Windows 7), and I would like to use URL Rewriting / Redirection. The reason I need to do this is because I can't change some mobile device code to just insert the parameter.

Here is the URL I want:

http://server.test.com/VirtualDirectory/theOrganization/RequestService.svc/REST/GetIssueTypes

The real URL is:

http://server.test.com/VirtualDirectory/RequestService.svc/REST/GetIssueTypes?organization=theOrganization

Notice how I want to remove theOrganization and appended it to the Query string for redirection.

<rule name="test" stopProcessing="true">
    <match url="(.+\.?)/(.+)/RequestService.svc/(.+)" />
    <action type="Redirect" url="{R:1}/RequestService.svc/{R:3}?organization={R:2}"
    redirectType="Permanent" />
</rule>

I know it's a little odd of a rule to write. Thinks i have my regular expression correct for matching. I run the expression in the URL Rewrite tester in IIS Manager, and it seems like it's matching what I want. Also, I do have IIS URL Rewrite installed, and I made a simple rule up and it worked.

However, when I try it using a browser, it failed to redirect and results in a 404. I was hoping a IIS Rewrite expert could chime in, as I am fairly new at it.

Thanks!

I tested your rule on a test server with iis 7.5 and url rewrite 2.0 and the rule is working, but your regex matches both your wanted url and the real url.

So you end up with a double redirect

I think you want your pattern something like this

(.+.?)/VirtualDirectory/(.+)/RequestService.svc/(.+)

Hope this helps.

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