Question

I have a podcast feed set up in an XML file, and my current subscribers subscribe to it using the direct file URL. (so http://website.com/feed.xml) I've been reading about how you can set up a COPY of that XML file with FeedBurner, force all future updates to be made on the FeedBurner file, and then just set up a redirect from the old XML url to the new FeedBurner URL in order to track subscribers (my main goal here).

http://underscorebleach.net/jotsheet/2005/07/feedburner-rss-migration

Unfortunately all of the tutorials I've seen on the subject assume I have an Apache server and I can modify the .htaccess file, so I've been fumbling with a way to get the same results on my MVC3 website.

So far I've tried 2 different ways:

Adding a url rewrite rule in the "system.webServer" section of my Web.config

<rewrite>
  <rules>
    <rule name="feedburner redirect" enabled="true" stopProcessing="true">
      <match url="feed.xml" ignoreCase="true" />
      <action type="Redirect" url="http://feeds.feedburner.com/NewFeed" appendQueryString="false" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_USER_AGENT}" pattern="FeedBurner" negate="true" />
      </conditions>
    </rule>
  </rules>
</rewrite>

This isn't working, and I'm also getting a warning in Visual Studio about how the "rewrite" element is not a valid child of "system.webServer", so I'm not sure if this is the correct implementation, but this is how I've seen other examples written.

The other way I've tried is creating a route that will change the HTTP response to a 301 redirect to the new FeedBurner URL if a request for the old URL is made.

Url Routing class:

namespace Routes
{
    public class UrlRoute : RouteBase
    {
        public static void RerouteUrls()
        {
            var httpContext = HttpContext.Current;
            string redirectLocation = "";

            const string status = "301 Moved Permanently";

            string currentUrl = httpContext.Request.Url.ToString().ToLower();

            if (currentUrl.Contains("feed.xml"))
            {
                redirectLocation = "http://feeds.feedburner.com/NewFeed";
            }
            else
            {
                // None of the criteria was met; do not redirect user.
                return;
            }

            // Redirect page
            httpContext.Response.Clear();
            httpContext.Response.RedirectLocation = redirectLocation;
            httpContext.Response.StatusCode = 301;
            httpContext.Response.Status = status;
            httpContext.Response.End();
        }

        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            RerouteUrls();

            return null;
        }

        public override VirtualPathData GetVirtualPath(RequestContext requestContext,
                                                   RouteValueDictionary values)
        {
            return null;
        }
    }
}

In Global.asax:

public static void RegisterRoutes(RouteCollection routes)
{
    //...

    routes.Add(new Routes.UrlRoute());

    //...
}

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    RegisterRoutes(RouteTable.Routes);

    Database.SetInitializer<EF4DataContext>(null);
}

But again, directly typing "feed.xml" into the address bar will show me old XML file, and the URL doesn't change.

I've also seen a lot of suggestions about setting up a new controller action that redirects to a new action, but in this case it's just a file, not a view action or a webpage, so I don't think that applies here.

Any guidance on this subject would be much appreciated!

Was it helpful?

Solution

Figured it out... I wasn't interpreting the "conditions" section of the URL rewrite rule. It was limiting the rewrite rule ONLY to requests from FeedBurner, when I want ALL requests to the old feed file to be redirected. So I just had to remove that section. I'm left with just this:

<rewrite>
    <rules>
        <rule name="feedburner redirect" enabled="true" stopProcessing="true">
            <match url="feed.xml" ignoreCase="true" />
            <action type="Redirect" url="http://feeds.feedburner.com/NewFeed" appendQueryString="false" />
        </rule>
    </rules>
</rewrite>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top