Translating query parameter keys in Rails
- Posted by alex on June 5th, 2007 filed in work, ruby on rails
UPDATE:
I have made the plugin publicly available.
Building beautiful URLs in Ruby on Rails is easy. One of the major reasons we chose Ruby on Rails as our development platform was because it gave us a lot of freedom in creating search engine friendly URLs for our search engine results pages (SERPs). Building nice paths that suggest a file-directory like structure to our site will help search engines like Google figure out how pages are related and how best to index and serve the pages. A url from our J2EE site looks like this:
http://www.yellowpages.com/sp/yellowpages/ypresults.jsp?refined_category=Pizza&DCSext.catReg=TopCat&q=pizza&rType=headingtext&id=1&p=1&prop22=TopCat&DCSext.CatValRegion=TopCat&referrer=2&pageName=catRes_pg&WT.cg_n=catRes_pg&v=3&t=0&st=CA&s=2&ci=Pasadena&_requestid=768376
This is confusing to search engines and users alike. Ruby on Rails enables us to easily build a routing configuration file that helps us build category search URLs that look like this:
http://www.yellowpages.com/Pasadena-CA/Pizza
Unfortunately, beyond the simple use case of one word search strings, things begin to get complicated. When building a search web application, it is important to keep the exact formatting of the user entered search terms for various reasons, and shoving search terms that contain punctuation into the path of a URL makes for really ugly looking URLs. Additionally, we don’t want multiple URLs pointing to the same content, so normalizing user entered search strings becomes necessary. Since our search engine strips out punctuation anyway, we can do the punctuation stripping at the application level in order to build canonical strings representing the content of a SERP.
#Not only are these URLs ugly, they are two different URL paths #pointing to the same content which makes Google a bit suspicious. http://www.yellowpages.com/Pasadena-CA/L+%26+L+BBQ http://www.yellowpages.com/Pasadena-CA/L%26L+BBQ #URL paths should have no punctuation (like in a file directory) #and should have normalized search terms. We should #maintain the originally entered search term in some other way. #The SERP should still display if the original search terms #are omitted. We will send URLs without original search terms #to google to be indexed. http://www.yellowpages.com/Pasadena-CA/L-L-BBQ http://www.yellowpages.com/Pasadena-CA/L-L-BBQ?q=L+%26+L+BBQ http://www.yellowpages.com/Pasadena-CA/L-L-BBQ?q=L%26L+BBQ #Note: Building URLs that are search engine friendly is a lot #different than building URLs that are programmer friendly. #When exposing a REST based local search API, we would use #RESTful routes to build URLs like this: http://api.yellowpages.com/locations/Pasadena+CA/listings/search.xml?name=L+%26+L+BBQ
The above solution gives us nice URLs, with a single URL Path pointing to the content, and still allows us to display feedback to the user about their entered search terms while maintaining a stateless application flow from search box to SERP.
Get the plugin.
June 20th, 2007 at 1:17 am
[…] After getting approval from the big boss, I’m now publishing my first rails plugin. This is a plugin I’ve previously talked about developing here and here. […]