移动IIS7 URL重写部分出来的web.config文件 [英] Moving IIS7 url rewrite section out of the web.config file

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

问题描述

我已经在我的web.config文件中一个配置部分具有所有重写规则类似下面的

I have made a config section in my web.config file that has all rewrite rules like the following

<rewrite>
        <outboundRules>
            <rule name="OutboundRewriteCatalogURL" preCondition="ResponseIsHtml1">
                <match filterByTags="A" pattern="^(.*/)Catalog\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" />
                <action type="Rewrite" value="{R:1}ctlg/{R:2}/{R:3}/" />
            </rule>
            <rule name="OutboundRewriteCategoryURL" preCondition="ResponseIsHtml1">
                <match filterByTags="A" pattern="^(.*/)ProductList\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Category=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" />
                <action type="Rewrite" value="{R:1}categ/{R:2}/{R:3}/{R:4}/" />
            </rule>
            <rule name="OutboundRewriteFullProductURL" preCondition="ResponseIsHtml1">
                <match filterByTags="A, Form, Img" pattern="^(.*/)Product\.aspx\?Catalog=([^=&amp;]+)&amp;(?:amp;)?Category=([^=&amp;]+)&amp;(?:amp;)?Product=([^=&amp;]+)&amp;(?:amp;)?Title=([^=&amp;]+)$" />
                <action type="Rewrite" value="{R:1}prd/{R:2}-{R:3}-{R:4}/{R:5}/" />
            </rule>
            <preConditions>
                <preCondition name="ResponseIsHtml1">
                    <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                </preCondition>
            </preConditions>
        </outboundRules>
        <rules>
            <rule name="RedirectCatalogURL" stopProcessing="true">
                <match url="^Catalog\.aspx$" />
                <conditions>
                    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" />
                </conditions>
                <action type="Redirect" url="Catalog/{C:1}/{C:2}" appendQueryString="false" />
            </rule>
            <rule name="RewriteCatalogURL" stopProcessing="true">
                <match url="^ctlg/([^/]+)/([^/]+)/?$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="Catalog.aspx?Catalog={R:1}&amp;Title={R:2}" />
            </rule>
            <rule name="RedirectCategoryURL" stopProcessing="true">
                <match url="^ProductList\.aspx$" />
                <conditions>
                    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Category=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" />
                </conditions>
                <action type="Redirect" url="categ/{C:1}/{C:2}/{C:3}" appendQueryString="false" />
            </rule>
            <rule name="RewriteCategoryURL" stopProcessing="true">
                <match url="^categ/([^/]+)/([^/]+)/([^/]+)/?$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="ProductList.aspx?Catalog={R:1}&amp;Category={R:2}&amp;Title={R:3}" />
            </rule>
            <rule name="RedirectProductURL" stopProcessing="true">
                <match url="^Product\.aspx$" />
                <conditions>
                    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    <add input="{QUERY_STRING}" pattern="^Catalog=([^=&amp;]+)&amp;Category=([^=&amp;]+)&amp;Product=([^=&amp;]+)&amp;Title=([^=&amp;]+)$" />
                </conditions>
                <action type="Redirect" url="prd/{C:1}-{C:2}-{C:3}/{C:4}" appendQueryString="false" />
            </rule>
            <rule name="RewriteProductURL" stopProcessing="true">
                <match url="^prd/([^/]+)-([^/]+)-([^/]+)/([^/]+)/?$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="Product.aspx?Catalog={R:1}&amp;Category={R:2}&amp;Product={R:3}&amp;Title={R:4}" />
            </rule>
        </rules>
    </rewrite>

它非常好,工作好,但我不希望有这些东西在web.config文件中,有没有办法让在外部配置文件重写配置?

Its very nice and working good but I dont want to have all these stuff in the web.config file , is there a way to have rewrite configuration in an external config file?

推荐答案

您可以将您的配置分割成几个文件,包括使用configSource属性的部件到主web.config文件,例如:

You can split your configuration into several files and include the parts into the main web.config file using the configSource attribute, e.g:

web.config中:

web.config:

  <system.web>
    ...
    <profile configSource="profile.config" />
    ...
  </system.web>

profile.config:

profile.config:

<profile>
  <properties>
    <add name="Name" type="String" />
    <add name="Age" type="Int32" />
  </properties>
</profile>

请参阅这个博客帖子或<一个href=\"http://stackoverflow.com/questions/2411184/can-a-web-config-read-from-an-external-xml-file\">this问题了解详情。

这篇关于移动IIS7 URL重写部分出来的web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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