重写IIS7中的URL [英] Rewriting URLs in IIS7

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

问题描述

我一直关注 http://learn.iis.net /page.aspx/806/seo-rule-templates/ ,这是在IIS7中创建SEO友好URL的近乎完美的指南。

I have been following http://learn.iis.net/page.aspx/806/seo-rule-templates/, which is a nearly perfect guide to creating SEO friendly URLs in IIS7.

我有一个问题虽然:

如果我创建一条规则来重写 www.domain.com/contact / 我进入网络.config:

If I create a rule to rewrite www.domain.com/contact/ I get in web.config:

<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="?p={R:1}" />
</rule>

但是我不能做 www.domain.com/contact/发送/

如果我创建一条规则来重写 www.domain.com/contact/send / 我进入web.config:

If I create a rule to rewrite www.domain.com/contact/send/ I get in web.config:

<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="?p={R:1}&amp;a={R:2}" />
</rule>

但是我不能做 www.domain.com/contact/

这两条规则都是这样做的,我看不到任何脚本,css og来自我的 / scripts的图像/ / css / / images / 文件夹。

Both of the rules do so that I can't see any scripts, css og images from my /scripts/, /css/ and /images/ folders.

如何制定规则以匹配AND与上述3个文件夹不匹配?

推荐答案

您的规则可能是这样的(我已经扩展并评论它以便更容易理解和最终编辑):

Your rule could be something like this (I have expanded and commented it for an easier understanding and eventual editing):

^
    (
        (?!css|scripts|images)  # The directories you don't want to match
        [^/]+                   # The matched directory
    )
    (
        /
        (
            ([^/]+)             # Optional part
            /?                  # Optional trailing slash
        )?
    )?
$

其中包含以下内容:

<match url="^((?!css|scripts|images)[^/]+)(/(([^/]+)/?)?)?$" />

然后,重写网址应更新为:?p = {R: 1}& amp; a = {R:4} ,因为新正则表达式的捕获次数发生了变化。

The rewrite url should then be updated to: ?p={R:1}&amp;a={R:4} because of the changes in the number of captures of the new regular expression.

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

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