We have an old domain on an old shopify site. We have a new domain on a new wordpress website.
Our goal is to re-direct all old links from the old site/domain to the new site domain.
For example if a user goes to www.old-website.com/collection/product
it will re-direct them to www.new-website.com/collection/product.
So basically i wana keep /collection/product but swap out the rest of the domain.
I am using this script but i think its too simple and just re-directing to the home page.
<script type="text/javascript">
window.location.href = "https://new-website.com"
</script>
So instead of simply changing the location to the new domain. How do I keep the directories but change the domain and then re-direct?
3
Answers
You can take the entire url (
document.location.href
) and split the parameters to append it to the new url.If your user will go to
www.old-website.com/collection/product
The entire path (except old domain) is appended to the new domain and the result url it will look like this
https://new-website.com/collection/product
If you are forced to do it with JavaScript, then simply try
Thinking a little out of the box. If you have access to the DNS, you can easily do that using use the redirect.center service.
You need to add / modify 2 records of the
old-website.com
zone:The advantage is that this is a 301 redirect which is better for SEO. Also you can remove your old website, possibly saving some bucks.