is it possible to redirect the hostname of the URL using javascript?
If URL contains "content/articles", it should remain in the same URL. Otherwise, it should redirect all other URLs from www to www1.
I think i got the "/content/articles" part but window.location.replace doesnt seem to work.
For example:
- https://www.abc.com.sg/content/articles will remain the same URL.
- https://www.abc.com.sg redirect to https://www1.abc.com.sg
<script type="text/javascript">
window.onload = function() {
if (window.location.href.indexOf("/content/articles") > -1) {
// Do not redirect
} else {
// Redirect from www to www1
window.location.replace(window.location.protocol + "//" + window.location.hostname.replace("www", "www1")+window.location.pathname);
}
}
</script>