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

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

问题描述

我尽我所能扫描论坛寻求帮助,制作一个 web.config 来重写这种 url

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

我希望这可以

domain.com/en/service

其中 language=2 是en"id=3 是页面服务"(这个名字存在于一个 mySQL 中)

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

像这样

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

这会将domain.com/en/service"重写为domain.com/default.asp?language=en&id=Service",或将domain.com/2/3"重写为domain.com/default.asp?language=2&id=3"

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"

要将 2 更改为 en,将 3 更改为 service,以及所有其他选项,但我认为您需要为每个排列设置单独的规则,或者在您的 asp 页面中有某种逻辑来读取您的查询字符串变量和将相应的值发送到您的 SQL 查询.还要注意,友好 url 中的参数和重写 URL 中的查询字符串变量以相同的顺序出现,尽管这应该不是问题.如果有人尝试使用原始不友好"网址访问页面,他们将找到他们正在寻找的内容,无论他们输入查询字符串变量的方式如何.

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.

请注意,我实际上并没有手动编写上面的规则,而是使用 IIS 管理器中的 URL Rewrite 模块生成的 - 它让生活变得更轻松

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

另请注意,正如在另一个答案中与我的同名讨论的那样,这仅适用于 IIS7 及更高版本

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

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

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