Beautify your ugly and poor SEO URLs in Drupal CMS

19 March 2013

The last issue we will deal with in this post is how to avoid displaying any link with unnecessary numerical IDs in the different country pages. We use a lot of views and the contextual filters only understand numerical IDs -- the same will happen if you use Panels -- so the question is how we can create SEO-friendly URLs.


There is an easy answer: create URL aliases for all the possible arguments of your views, panels, etc. However, if you have 20 countries and with the possibility of more to come, this approach is not practical.


The solution here is actually based on an enabling good practice. One of the best practices we use at Bluespark is to have a unique feature for every content type and add all its components inside that feature. For this example site we have:

1.    ct_article – feature for articles
2.    ct_news – feature for news
3.    ct_event – feature for events


This means that we have a module for every content type, and we also have a view filtered by country for every one that will also be contained in its own feature.


With this architecture in place we can easily connect with APIs from other modules (such as Pathauto), so we can integrate custom Pathauto patterns for our content types such as news/1, news/2, etc. or events/1, events/2, etc. Implementing a hook_pathauto() in every content type feature will allow for custom configuration of the auto pattern URL of our content:


In this example our Articles page is filtered by categories (taxonomy terms), so we want our view URL (which is actually articles/1, articles/2, etc.) to be displayed as style/tips, style/health, etc. We provide a default pattern via Pathauto style/[term:name], where [term:name] will be replaced by the term name of every new category added, updated, or deleted. Reacting on these events and calling the function pathauto_create_alias allows us to dynamically add a URL alias for any possible URL for our View that we know is composed by different taxonomy terms of a specific vocabulary.


So we also implement in our ct_article.module the following hooks:
1.    hook_taxonomy_term_insert() - call pathauto_create_alias
2.    hook_taxonomy_term_update() - call pathauto_create_alias
3.    hook_taxonomy_term_delete() - call pathauto_entity_path_delete_all


The same implementation will be adapted to all our different content types, creating on-the-fly all the aliases that we need for our custom pages (views, panels, or custom modules).


Done! We now have a complete solution for a multi-country site with a relatively simple approach, using a small number of modules whilst following the Drupal principles of reuse and override. We hope this will be useful for people out there. Please share your experience and comments on similar problems with us!


Drupal Web Development San Jose

Why Fortune Innovations?

  • Cost-saving for your projects, up to 40%
  • Hire web development and web designing specialists
  • Project management based out in San Jose
  • 50 plus strong off shore development team based in Bangalore, India
  • Expert teams well verse with Web 2.0 standards
  • Quality-driven delivery model
  • Detailed time sheets, daily reporting and regular status updates
  • WordPress Development in San Jose
  • Drupal Development in San Jose
  • Joomla Development in San Jose
  • eCommerce Magento San Jose
  • Web Development San Jose
  • Web Design San Jose
  • jQuery development San Jose
  • Zend framework development San Jose
  • Airline IBE GDS Integration Navitaire San Jose
  • Airline IBE GDS Integration Aamadeus San Jose