Question

I have an external "rewritemaps.config" file with the following entries:

<rewriteMaps>  

    <rewriteMap name="Cat1">
        <add value="2" key="wheels-and-castors" />
        <add value="3" key="agricultural" />
        <add value="4" key="hydraulic-hose-and-fittings" />
        <add value="5" key="engineering-plastics" />
        <add value="6" key="sealing-and-jointing" />
        <add value="7" key="health-and-safety" />
        <add value="8" key="hose-and-ducting" />
        <add value="9" key="hose-couplings-and-clamps" />
        <add value="10" key="general-consumables" />
        <add value="11" key="ceramics" />
        <add value="12" key="rubber-and-polyurethane" />
    </rewriteMap>

</rewriteMaps>

How do I rewrite URL's such as: http://www.domain.com/wheels-and-castors/

to the following: http://www.domain.com/category.asp?catID=2

Note, this is a rewrite, and not a redirect.

I think I'm almost there with the final rewrite line, but I'm struggling on the match and conditions. My current final rewrite line is:

<action type="Rewrite" url="category.asp?catID={Cat1:{C:1}}" appendQueryString="false" />

(where Cat1 is the name of my rewriteMap)

Thanks for any help. Cheers, Chris.

Was it helpful?

Solution

Ok, after a good week of researching and trial & error, I've got it working. Here's the complete rule I'm using, which references an external "rewritemaps.config".

<rule name="Match Category URLs" stopProcessing="true">
    <match url="^(?![^/]+?\.(?:css|png|jpg|axd)$)([^/]+)/?$" />
    <conditions>
        <add input="{URL}" pattern="(.asp|.xml)" negate="true" />
    </conditions>
    <action type="Rewrite" url="category.asp?catID={CatMap:{R:1}}" appendQueryString="false" />
</rule>

Works perfectly now.

PS. I renamed the rewriteMap to "CatMap" (to avoid anyone getting confused, if following this).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top