printing a url with variables
<p><strong>TLDR</strong></p>

<p>I want to print this  </p>

<pre><code>&lt;link rel="canonical" href="http://nyc.mymusicwebsite.com/coolband/1222
"/&gt;
</code></pre>

<p>where</p>

<pre><code>var termsText = nyc
var deliurl = http://nyc.mymagazine.com/coolband/122
deliurl2[1] = mymagazine
deliurl[2] = .com/coolband/122
</code></pre>

<p>(deliurl is split at .)
I have this code so far which almost works, This is the problem</p>

<pre><code>document.write('&lt;link rel=cononical"'+" ""href="http:"//"""+termsText+"."+deliurl2[1]+deliUrl[2]'"/&gt;');
</code></pre>

<p>I have a drupal website that creates duplicate content for every post, </p>

<p>every post creates multiple pages</p>

<pre><code>http://nyc.mymusicwebsite.com/coolband/1222
http://national.mymusicwebsite.com/coolband/1222
http://seatle.mymusicwebsite.com/coolband/1222
http://la.mymusicwebsite.com/coolband/1222
</code></pre>

<p>though only one post is visible on the website the other posts are getting indexed.</p>

<p>the posts above are all tagged in a div with the region they are assigned and visible on the website.  </p>

<p>I want to print the google rel conical link, linking to the conincal post.  this post would have the subdomain identical to the pages tag in the div.</p>

<p>I have done everything except printing the url</p>

<p>consider the following code</p>

<pre><code>    //find tag in page for pattern match
    var termsText = $("#terms").find("ul li:last").text(); 

    //get window location url to test agains pattern
    var deliUrl=window.location.href


    //test pattern
    var patt1=new RegExp(termsText);


    //split url at first period to isolate everything after the subdomain
    var deliUrl2=deliUrl.split('.');


    //if pattern is NOT in url print google conical tag pointing to propper subdomain
    if (patt1.test(deliUrl));

    {
        //print subdomain as "terms" and rest of url
        document.write('&lt;link rel=cononical"'+" ""href="+termsText+"."+deliurl2[1]+deliUrl[2]'"/&gt;');

}
</code></pre>
