Link 重定向协助

Link redirecting assistance

这是脚本:

<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>

问题是,我该如何编写代码,以便当我输入 https://thedomain.com/////////////////////////////////////////collections/all?sort_by=best-selling

如何合并 var correctURL= document.location.href.replace(/([^:]/)/+/g, "$1"); 每当我复制任何“/”“?”网络中的“_”“=”“-”字符link。

底线是我不想被迫这样做(效率低下):

<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>

我不是 100% 确定您在问什么,或者为什么您的 url 中会有那么多斜线,但您可以只匹配 url 的一部分以查看如果用户在正确的页面上。

if(document.location.href.indexOf('/collections/all?sort_by=best-selling') > -1) { 

     document.location.href = 'https://thedomain.com/pages/bestsellers';
}