繁体   English   中英

使用IIS7重写URL

[英]URL Rewriting with IIS7

我有一个在IIS7上托管的网站,我想在网上重写网址

我当前的网址blog.mysite.com/article.aspx?name=marriage

我想重写它

blog.mysite.com/marriage

我尝试了一些规则,但没有给出完美的解决方案。

请分享您的想法,对我有所帮助

谢谢你们

世斌

假设您使用的是Microsoft Rewrite 2.0,那么您的模式将是:

^([^ /] +)/?$

您的重写URL将是:

?article.aspx名= {R:1}

要简单地从新的url方案重定向到旧的把它放在web.config的system.webserver部分中:

<rewrite>
  <rules>
    <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="article.aspx?name={R:1}" />
    </rule>
  </rules>
</rewrite>

还要从旧网址重定向到新网址,因此旧网址会自动更新到新方案,并包含将重写您的html输出以使用新网址方案的处理,您可以将以上内容替换为:

<rewrite>
  <rules>
    <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
      <match url="^article\.aspx$" />
      <conditions>
        <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
        <add input="{QUERY_STRING}" pattern="^name=([^=&amp;]+)$" />
      </conditions>
      <action type="Redirect" url="{C:1}" appendQueryString="false" />
    </rule>
    <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="article.aspx?name={R:1}" />
    </rule>
  </rules>
  <outboundRules>
    <rule name="OutboundRewriteUserFriendlyURL1" preCondition="ResponseIsHtml1">
      <match filterByTags="A, Form, Img" pattern="^(.*/)article\.aspx\?name=([^=&amp;]+)$" />
      <action type="Rewrite" value="{R:1}{R:2}/" />
    </rule>
    <preConditions>
      <preCondition name="ResponseIsHtml1">
        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
      </preCondition>
    </preConditions>
  </outboundRules>
</rewrite>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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