Multiple robots.txt for subdomains in rails

后端 未结 6 2085
轻奢々
轻奢々 2021-01-31 23:21

I have a site with multiple subdomains and I want the named subdomains robots.txt to be different from the www one.

I tried to use .htaccess, but the FastCGI doesn\'t lo

6条回答
  •  情歌与酒
    2021-01-31 23:46

    Why not to use rails built in views?

    In your controller add this method:

    class StaticPagesController < ApplicationController
      def robots
        render :layout => false, :content_type => "text/plain", :formats => :txt
      end
    end
    

    In the view create a file: app/views/static_pages/robots.txt.erb with robots.txt content

    In routes.rb place:

    get '/robots.txt' => 'static_pages#robots'
    

    Delete the file /public/robots.txt

    You can add a specific business logic as needed, but this way we don't read any custom files.

提交回复
热议问题