Reputation: 11
I have changed my domain name and i really don't want to go through the trouble of making all the links i have posted in the articles in my website to the domain name. Is there a code i can use to make all the links to the old domain change.
For example, if i have a link somewhere that is oldurl.com/faq and i want it to change to newurl.com/faq
But without rewriting it manually, so it does it for all the links on my website that start with oldurl.com
How would i do this?
Upvotes: 1
Views: 461
Reputation: 1185
This is the quick and lazy way to do it.
$(function(){
$('a').attr('href', function(x, url){
return url.replace('oldurl.com', 'newurl.com');
});
});
Upvotes: 0
Reputation: 71394
You can point the DNS for the old domain to the new domain, and place a redirect rule in the webserver to rewrite to the proper domain.
This is probably something you should do anyway to have any external links that you have no control over be pointed to the proper new location.
This however is not a substitute for fixing your actual links. You should fix these as well. In fact it is usually best proactice to not include the full URL on internal site links, instead using only URI's or relative paths for such links.
Most any good IDE will give you the ability to search and replace across all file in a site, so doing this should not be too painful.
Upvotes: 1