Plugins - webmaster_verification
Add to favoritesThis plugin adds support for Google, Yahoo! and Live webmaster tool authorization for multiple webmasters.
Google, Yahoo! and Live (MSN) all have online tools for webmasters. Each site requires that users verify ownership by either adding meta tags to pages on the site or upload specially-named HTML files.
- Google Webmaster Tools - https://www.google.com/webmasters/tools/
- Yahoo! Site Explorer - https://siteexplorer.search.yahoo.com/
- MSN Live Webmaster Tools - http://webmaster.live.com/
Before this plugin there were 2 ways to add these files to your site:
- Add custom routes and a controller to handle them
- Keep the files in the public directory.
Whenever a new webmaster needs authorization, you would add a route or add a physical HTML file, and the next site you worked on, you’d have to do the same.
Adding routes was simple and easy, but every time you updated the app you needed to restart the server. Adding files didn’t require a server restart, but added a lots of ugly files to the app.
This plugin allows you to add users by adding an entry to a config file so you don’t have to store physical files, and you don’t have to add routes or restart the server (the yaml config is not cached).
In addition, it allows you to keep track of who owns what, in case you ever need to revoke ownership.
Installation
Via Git:
git clone git://github.com/zilkey/webmaster_tools.git vendor/plugins/webmaster_tools
To install, simply run
script/generate webmaster_verification
The generator creates a file named config/webmaster_verification.yml and adds a map.webmaster_verification to config/routes.rb
Acknowledgments
Part of this plugin was based on (read shamelessly-stolen-from) the Jamis Buck’s excellent series on routing at http://weblog.jamisbuck.org/2006/10/20/monkey-patching-rails-extending-routes-1
config/webmaster_verification.yml
All of the webmasters verification codes are all stored in a single config file.
You can add several different webmaster to each search engine, or no webmasters at all, and the names don’t have to be the same from one browser to the next - they are just there to make it easy to identify who owns what.
To make it easier, you can also specify people’s email addresses.
When you make changes to this file, you do not need to restart the server
A sample file might look like:
google:
someone@example.com: google121212.html
edna: google131415.html
betty: google3435365.html
yahoo.com:
eugene:
filename: y_key_185746.html
content: 098374
edna:
filename: y_key_185746.html
content: 323454
live:
edna: 6565656564734839
map.webmaster_verification
map.webmaster_verification takes all of the entries in the config file and turns them into routes for Google and Yahoo! and installs the route to the Live xml file.
The route, once installed, looks like:
ActionController::Routing::Routes.draw do |map|
map.webmaster_verification
end
Once installed, and you’ve put entries into routes.rb, run
rake routes
and you will notice routes that look like:
/google5e12de32b7292ab0.html {:controller=>"zilkey/routing/webmaster_verification", :action=>"google"}
/y_key_7c13d2bfdaa79c25.html {:controller=>"zilkey/routing/webmaster_verification", :action=>"yahoo", :content=>"111e174241ecc5e0"}
/LiveSearchSiteAuth.xml {:format=>"xml", :controller=>"zilkey/routing/webmaster_verification", :action=>"live"}
WebmasterVerificationController
Behind the scenes, the routes map to a controller named Zilkey::Routing::WebmasterVerification. This controller renders the content directly, and does not modify view paths so there is little chance of naming conflicts.
You should note that WebmasterVerificationController inherits directly from ActionController::Base, so none of your before filters will apply. If you need before_filters, you can monkey-patch WebmasterVerificationController.
Caching
No caching occurs in any part of this process - every time Google, Yahoo! or Live request the page, the config file is loaded from disk, and the controller renders the response.
