Sitefinity and URL Rewriting

Posted by Community Admin on 03-Aug-2018 00:17

Sitefinity and URL Rewriting

All Replies

Posted by Community Admin on 03-Oct-2012 00:00

We have a new Sitefinity site that is replacing our marketing site. The switchover happened last friday, and we uncovered a problem today: there is content (pdfs, jpgs) on the old site that can no longer be accessed, and did not make it into the content migration plan. On top of that, management has removed rollback as an option, and the old site is referenced in so many places that content migration is not a foolproof solution

So, the solution I have come up with is to use IIS 7's url rewriting module to point to a new url that hosts the old site so that content can be accessed. This is the xml in my web.config that I have come up with:

<rewrite>
    <rules>
        <rule name="RedirectFileNotFound" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">
                <add input="REQUEST_FILENAME" matchType="IsFile" pattern="" ignoreCase="true" negate="false" />
                <add input="REQUEST_FILENAME" matchType="IsDirectory" pattern="" ignoreCase="true" negate="false" />
            </conditions>
            <action type="Redirect" url="http://www.oldsite.comREQUEST_URI" redirectType="Temporary" appendQueryString="true" />
        </rule>
    </rules>
</rewrite>

It attempts to test if the URL resolves to a file or folder. If the rules pass, it redirects to the same location on the old site. Ideally, this would mean that anything linking to the old site previously would be able to be left alone.

The problem is, nothing gets redirected.

By fiddling with the rules, I have verified that the module is operational, i.e. i can set it up to rewrite everything, and it works. but these rules do not work.

My theory is that since Sitefinity uses database storage, it somehow short circuits the "IsFile" match type. Complete guess, but I'm kind of at a loss at this point.

How to I use urlrewriting to redirect for 404's in this manner?

Posted by Community Admin on 03-Oct-2012 00:00

I am not a URL Rewrite expert but I believe that those rules will never match because the files and directories don't exist in a Sitefinity site. they are all virtual. Url Rewrite is looking for physical files.
I woud sugest transferring those rules to your global.asax file in the on App_Error event and test for a httpexception and .GetHttpCode() method a check if it equels 404.

Posted by Community Admin on 03-Oct-2012 00:00

Yes, I believe that a library request needs to make it to the httphandler before it can be invalidated... by which time the IIS URL-Rewrite module is out of the picture.

If entire libraries are missing, you could probably redirect based on pattern-matching the request url... something like:  ^librarytype/libraryname/(.*)$  and redirect using R:1 as the capture

Otherwise, catching and redirecting 404's - could be done I guess.

This thread is closed