3
重寫我有一個網站託管在IIS7和我想impliment網址就可以重寫URL與IIS7
我現在的URL blog.mysite.com/article.aspx?name=marriage
我想它重寫
blog.mysite.com/marriage
我嘗試了一些規則,但沒有給出完美的解決方案。
請分享你的想法和將是對我有幫助
謝謝大家
世斌
重寫我有一個網站託管在IIS7和我想impliment網址就可以重寫URL與IIS7
我現在的URL blog.mysite.com/article.aspx?name=marriage
我想它重寫
blog.mysite.com/marriage
我嘗試了一些規則,但沒有給出完美的解決方案。
請分享你的想法和將是對我有幫助
謝謝大家
世斌
假設你正在使用微軟重寫2.0那麼你的模式將是:
^([^/] +)/?$
而你的重寫網址是:
?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>
爲了也做從舊到新的url重定向,所以舊的網址會自動更新到新的方案,幷包括處理將重寫您的html輸出使用新的url方案,您可以用上面的替換上述:
<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=([^=&]+)$" />
</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=([^=&]+)$" />
<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>