1

XML ファイルで設定されたポッドキャスト フィードがあり、現在の購読者はファイルの直接 URL を使用してそれを購読しています。(つまりhttp://website.com/feed.xml ) FeedBurner を使用してその XML ファイルの COPY を設定し、今後のすべての更新を強制的に FeedBurner ファイルに適用する方法について読んだことがあります。購読者を追跡するために、古い XML URL から新しい FeedBurner URL へのリダイレクトを作成します (ここでの主な目標)。

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

残念ながら、この件に関して私が見たすべてのチュートリアルは、Apache サーバーがあり、.htaccess ファイルを変更できることを前提としているため、MVC3 Web サイトで同じ結果を得る方法を手探りしてきました。

これまでのところ、私は2つの異なる方法を試しました:

Web.config の「system.webServer」セクションに URL 書き換えルールを追加する

<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>

これは機能せず、「rewrite」要素が「system.webServer」の有効な子ではないという警告も Visual Studio で表示されるため、これが正しい実装かどうかはわかりませんが、これは私が書かれた他の例を見た方法です。

私が試したもう 1 つの方法は、古い URL に対する要求が行われた場合に HTTP 応答を新しい FeedBurner URL への 301 リダイレクトに変更するルートを作成することです。

URL ルーティング クラス:

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;
        }
    }
}

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);
}

ただし、アドレス バーに「feed.xml」と直接入力すると、古い XML ファイルが表示され、URL は変更されません。

また、新しいアクションにリダイレクトする新しいコントローラー アクションを設定することに関する多くの提案も見てきましたが、この場合は単なるファイルであり、ビュー アクションや Web ページではないため、ここでは当てはまらないと思います。

この件に関するガイダンスをいただければ幸いです。

4

1 に答える 1

0

わかりました... URL書き換えルールの「条件」セクションを解釈していませんでした。古いフィード ファイルへのすべてのリクエストをリダイレクトする場合、FeedBurner からのリクエストのみに書き換えルールを制限していました。そのため、そのセクションを削除する必要がありました。私はこれだけが残っています:

<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>
于 2012-06-29T02:58:58.923 に答える