Here's the code snippet:
<script>
if(document.location.href.indexOf('https://thedomain.com/collections/all?sort_by=best-selling') > -1) {
document.location.href = 'https://thedomain.com/pages/bestsellers';
}
</script>
I am wondering how I can modify the code to handle URLs that contain repeated "/" "?" "_" "=" "-" characters, like .
Is there a way to include the following expression: var correctURL = document.location.href.replace(/([^:]/)/+/g, "$1"); to automatically handle duplicated characters in the URL?
Ultimately, I want to avoid manually adjusting the URL in the script each time:
<script>
if(document.location.href.indexOf('https://thedomain.com/////////////////////////////////////////collections/all?sort_by=best-selling') > -1) {
document.location.href = 'https://thedomain.com/pages/bestsellers';
}
</script>