Have a website where you are having issues with some subdomains because you have several different environments all sitting on seperate subdomains? (dev.integgroll.com,test.integgroll.com,www.integgroll.com) for example.

But wait while on each of those you have to link to other subdomains and they all need to be dependant too!  (railsdev.integgroll.com, itsacardigantest.integgroll.com)

Well I did.  And to solve the issue of having to constantly edit each domain individually I wrote the following script, Enjoy.

$(document).ready(function(){
  if(!window.location.hostname.match(/^www\./)){
  var split_hostname = window.location.hostname.split(/\./);
    $("a.domain_specific").each(function(e,i){
      var split_link = $(this).attr("href").split(/\./);
      split_link[0] = split_link[0].replace(/^www/,)+split_hostname[0];
      $(this).attr("href",split_link.join(‘.’));
    })
  }
})