2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【Rails】生成sitemap

Last updated at Posted at 2016-01-24

安装

Gemfile
gem 'sitemap_generator'

生成config/sitemap.rb

bundle exec rake sitemap:install

修改SitemapGenerator::Sitemap.default_host

config/sidemap.rb
SitemapGenerator::Sitemap.default_host = 'http://example.com'

在public/下生成sitemap文件

# Development/Test环境
bundle exec rake sitemap:refresh:no_ping

# Production环境
bundle exec rake sitemap:refresh

结果如下:

rake sitemap:refresh:no_ping
> In /app_path/to/public/
> + sitemap1.xml.gz                                          1 links > /  340 Bytes
> + sitemap_index.xml.gz                                  1 sitemaps > /  241 Bytes
> Sitemap stats: 1 links / 1 sitemaps / 0m00s

修改Robots.txt

Robots.txt
Sitemap: http://www.example.com/sitemap.xml.gz

Deployments & Capistrano

require 'capistrano/sitemap_generator'

可使用的命令:

deploy:sitemap:create   #Create sitemaps without pinging search engines
deploy:sitemap:refresh  #Create sitemaps and ping search engines
deploy:sitemap:clean    #Clean up sitemaps in the sitemap path

参考网站

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?