简体   繁体   English

URL重写asp.net IIS

[英]URL rewriting asp.net IIS

I'm trying to rewrite the URL in IIS URL rewriter module. 我正在尝试在IIS URL重写器模块中重写URL。

I've to convert the following url: 我必须转换以下网址:

websitename/Pages/Products.aspx?Category=10-Dishwashers

to

websitename/pages/products/category/dishwashers

I've tried something like this: 我已经尝试过这样的事情:

^Pages/Products.aspx?Category=10 (REGEX) ^ Pages / Products.aspx?Category = 10(REGEX)

action: pages/product/category/diswashers 动作:页面/产品/类别/洗碗机

I'm new to this. 我是新来的。 I don't know how to proceed. 我不知道该如何进行。 Any help? 有什么帮助吗?

I'm assuming your question is about the reverse, in other words from having a nice clean URL (no query string), to get back to the one that includes the "id" in the query string, so that your customers don't need to see that numeric ID. 我假设您的问题是相反的,换句话说,就是拥有一个很好的整洁的URL(没有查询字符串),然后返回到在查询字符串中包含“ id”的那个,这样您的客户就不会需要查看该数字ID。

If that is the case, then what I would recommend is using a rewriteMap where you can have that mapping and then you can have friendly names for the categories and resolve to whatever numeric ID is, for example if you add the below in a web.config it will match the nice URL and transform it into the .aspx?Category format : 如果是这种情况,那么我建议您使用rewriteMap,在其中您可以具有该映射,然后可以为类别指定友好名称并解析为任何数字ID,例如,如果将以下内容添加到Web中。 config它将匹配好的URL并将其转换为.aspx?Category格式:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="RewriteCategory">
                    <match url="pages/products/category/(.*)" />
                    <action type="Rewrite" url="pages/products.aspx?Category={CategoryMap:{R:1}}" />
                </rule>
            </rules>
            <rewriteMaps>
                <rewriteMap name="CategoryMap" defaultValue="other">
                    <add key="dishwashers" value="10-Dishwashers" />
                    <add key="something" value="20-s" />
                    <add key="anotherkey" value="30-another" />
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    </system.webServer>
</configuration>

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

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