1

The following case:

A visitor comes in on http://www.example.com/pretty. This gets redirected to http://www.example.com/?ID=ugly. This part works.

However, we'd like the visitor to keep seeing http://www.example.com/pretty in the address bar of his browser, instead of http://www.example.com/?ID=ugly.

We've tried various combinations in the URL Rewrite module, but none seem to get us the desired result.

Is this even possible?

2
  • 1
    Presumably you've already tried <action type="Rewrite" as opposed to "Redirect"? Also bear in mind that if this was previously an external redirect, then it's likely that it was cached by the browser, so you will need to ensure all caches are cleared before testing. – MrWhite Dec 2 '15 at 14:44
  • We've tried quite a few permutations, yes :) Redirect example.com/pretty -> example.com/?ID=ugly shows the correct page, with the ugly URL. Rewrite example.com/pretty -> example.com/?ID=ugly gives a 404.4 with the pretty URL. – Evert Dec 3 '15 at 8:24
1

This eventually did the trick.
ugly URL: www.domain.com/?CatID=1167
pretty URL: www.domain.com/people

<rewrite>
    <rules>
        <rule name="Redirect /people" enabled="true" stopProcessing="true">
            <match url="^$" />
            <conditions>
                <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                <add input="{QUERY_STRING}" pattern="^catid=1167$" />
            </conditions>
            <action type="Redirect" url="/people" appendQueryString="false" />
        </rule>
        <rule name="Rewrite /people" enabled="true" stopProcessing="true">
            <match url="^people$" />
            <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="?catid=1167" />
        </rule>
    </rules>
    <outboundRules>
        <rule name="OutboundRewrite /people" preCondition="ResponseIsHtml1" stopProcessing="false">
            <match filterByTags="A, Form, Img" pattern="catid=1167$" />
            <action type="Rewrite" value="/people" />
        </rule>
        <preConditions>
            <preCondition name="ResponseIsHtml1">
                <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
            </preCondition>
        </preConditions>
    </outboundRules>
</rewrite>
2
  • Thanks for the feedback. So, what actually was the problem with your original code? – MrWhite Dec 3 '15 at 11:19
  • 1
    Most likely something in the regex, the order, the patterns, or whatnot. The above mentioned config we got by using the 'User-friendly URL' template, and butchering it in such a way that instead of turning 1 pattern into another pattern it would turn 1 specific URL into another one... :) – Evert Dec 3 '15 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.