IIS URL重写ASP [英] IIS URL Rewrite ASP

查看:143
本文介绍了IIS URL重写ASP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尽我所能来扫描帮助论坛上作出的web.config做这种URL的一个重写

  domain.com/default.asp?id=3&language=2

我的希望是,这可能是

domain.com/en/service

其中,语言= 2 是EN
ID = 3 是网页服务(这个名字在MySQL存在)

我只能找到例子,做反之亦然...

筛选

 <&改写GT;
  <规则与GT;
    <规则名称=查询stopProcessing =真>
      <匹配URL =^ $查询/>
      <作用TYPE =重写URL =/ page.asp/>
    < /规则>
  < /规则>
< /重写>

我想它是这样的......我知道这是不正确的,但也许解释了我的问题。

 <&改写GT;
  <规则与GT;
    <规则名称=查询stopProcessing =真>
     <匹配URL =^ Default.asp的ID = 3&安培;语言= 2 $/>
     <作用TYPE =重写URL =/ EN /贡献莫过于/>
    < /规则>
  < /规则>
< /重写>


解决方案

如果您要使用正规前pressions你可以做这样的事情。

 <规则名称=RewriteUserFriendlyURL1stopProcessing =真>
     <匹配URL =?^([^ /] +)/([^ /] +)/ $/>
         <条件>
             <添加输入={} REQUEST_FILENAME使用MatchType =ISFILE否定=TRUE/>
             <添加输入={} REQUEST_FILENAME使用MatchType =IsDirectory否定=TRUE/>
         &所述; /条件>
     <作用TYPE =重写URL =Default.asp的语言= {R:1}?&放大器;放大器;编号= {R:2}/>
< /规则>

这将改写domain.com/en/service作为domain.com/default.asp?language=en&id=Service或domain.com/2/3作为domain.com/的default.asp语言= 2及?编号= 3

要改变2恩和3服务,与所有其他选项一起,虽然我认为你需要为每个排列一个单独的规则,或你的ASP页面内有某种逻辑来阅读你的查询字符串变量发送相应的值到你的SQL查询。还要注意的是在友好的URL参数出现在相同的顺序,并在重写URL查询字符串变量,虽然这实在不应该是一个问题。如果有人试图用原来的不友好的URL访问的页面,他们将找到他们所寻找的,无论怎样轮他们进入查询字符串变量。

请注意,我其实没有手code以上的规则,我在IIS管理器的URL重写模块生成的 - 它让生活变得更加简单。

另外请注意,我在对方的回答同名讨论的,这仅适用于IIS7及以上

I do my best to scan the forum for help to make a web.config to do a Rewrite of this kind of url

domain.com/default.asp?id=3&language=2

My hope is that this can be

domain.com/en/service

where language=2 is "en" and id=3 is page "Service" (this name exist in a mySQL)

I can only find example that do it vice versa...

Like this

<rewrite>
  <rules>
    <rule name="enquiry" stopProcessing="true">
      <match url="^enquiry$" />
      <action type="Rewrite" url="/page.asp" />
    </rule>
  </rules>
</rewrite>

I would like it to be something like this... I know this isn't correct, but maybe explains my problem.

<rewrite>
  <rules>
    <rule name="enquiry" stopProcessing="true">
     <match url="^default.asp?id=3&language=2$" />
     <action type="Rewrite" url="/en/serice" />
    </rule>
  </rules>
</rewrite>

解决方案

If you want to use regular expressions you could do something like this

<rule name="RewriteUserFriendlyURL1" 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="default.asp?language={R:1}&amp;id={R:2}" />
</rule>

This would rewrite "domain.com/en/service" as "domain.com/default.asp?language=en&id=Service", or "domain.com/2/3" as "domain.com/default.asp?language=2&id=3"

To change the 2 to en and the 3 to service, along with all the other options though I think you would need a separate rule for each permutation, or have some sort of logic within your asp pages to read your querystring variables and send the corresponding values to your SQL queries. Note also that the parameters in the friendly url appear in the same order and the querystring variables in the rewritten URL, although this shouldn't really be an issue. If someone tries to access the page with the original "unfriendly" url they will find what they are looking for, whichever way round they enter the querystring variables.

Please note, I didn't actually hand code the rule above, I generated it with the URL Rewrite module in IIS manager - it makes life a lot easier

Also note, as discussed with my namesake in the other answer, this only applies to IIS7 and above

这篇关于IIS URL重写ASP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆