 <p><div class="snippet" data-lang="js" data-hide="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>var url = 'http://website.com/testing/test2/', //URL to convert lastSlash = url.lastIndexOf('/'), //Find the last '/' middleUrl = url.substring(0,lastSlash); //Make a new string without the last '/' lastSlash = middleUrl.lastIndexOf('/'); //Find the last '/' in the new string (the second last '/' in the old string) var newUrl = middleUrl.substring(0,lastSlash); //Make a new string that removes the '/' and everything after it alert(newUrl); //Alert the new URL, ready for use</code></pre> </div> </div> </p> <p>This works.</p>