Ruby on Railsアプリケーションは、次のコントローラコードを使用してsitemap.xmlファイルを生成します。Railsの古くは? sitemapのメソッドは常にHTTP 200を返します
class SitemapController < ApplicationController
layout nil
def index
headers['Content-Type'] = 'application/xml'
last_post = Post.last
if stale?(:etag => last_post, :last_modified => last_post.updated_at.utc)
respond_to do |format|
format.xml { @posts = Post.sitemap } # sitemap is a named scope
end
end
end
end
コンテンツが変更されていない場合、stale?
メソッドはHTTP 304 Not Modified応答を保証する必要があります。しかし、私がカールやWebブラウザを使ってこれをテストするたびに、常にHTTP 200が得られます。
$ curl --head localhost:3000/sitemap.xml HTTP/1.1 200 OK Connection: close Date: Mon, 13 Apr 2009 15:50:00 GMT Last-Modified: Wed, 08 Apr 2009 16:52:07 GMT X-Runtime: 100 ETag: "5ff2ed60ddcdecf291e7191e1ad540f6" Cache-Control: private, max-age=0, must-revalidate Content-Type: application/xml; charset=utf-8 Content-Length: 29318
stale?
メソッドを正しく使用していますか?これをローカルでテストすることも可能ですか?
ありがとうございました。 –
それは素晴らしいです、私はあなたに役立つことを望んでいた。更新していただきありがとうございます! –