Manipulating url with javascript

Asked

Viewed 1,165 times

1

I own a blog and migrated platform (Blogger -> Wordpress) and I also changed the domain. For newer articles I do not face any problem, however articles older than one or two years, there are links spread across the web with the old domain.

I need to manipulate the URL as follows:

When the user accesses the link, for example:

http://www.site1.com/2015/05/artigo_a

You are shown a message saying that the blog has changed its address and a link is generated according to the URL of the active page (I prefer this to automatically redirect the user, however, I do not rule out this solution) :

http://www.site2.com/2015/05/artigo_a

The domain is different, however the structure of the URL is the same on both platforms.

I read some tutorials about this with PHP, however, in Blogger I can only work with HTML and javascript.

  • Is the old domain in your name? You have access to it?

  • Yes @Sergio, is a domain ".blogspot.com", the new domain is ".blog.br"

  • I think it would be better to do this redirect where you have the domain registered. A simple "forward".

  • It turns out that the first (old) domain is on Google’s servers and the second (new) one is on a server I hired and in this case I can only redirect the domains registered on this server.

  • 1

    What is the Google product/service you contracted? Can’t you download the domain? or simply park the phone and forward?

1 answer

2


Here is an example>>

<script> 
var ok = window.location.pathname; 
window.open('http://linkdowebsitenovo.com/' +ok +window.location.search, target="_self");
document.write('<center><p><h4>O Website Movido.<p>Redirecionando</p><p>Caso não seja redirecionado automáticamente </h4><h2><br><a href="" onclick="javascript:window.location="http://linkdowebsitenovo.com'+ window.location.pathname +' '+ window.location.search +'">Clique aqui.</a></p></h2></br>');
</script>

I hope it was helpful. : ) [I couldn’t be sure what you want to do..]

  • This response implies having 2 online sites when the redirect should be done via at the previous level. Domain redirect, or less bad on htaccess, a little worse on PHP and a little worse on HTML head with metatags. Do so in Javascript (I think) which is the worst solution. Until because the search engines will not have the code of redirect

  • (y) Yes, More was answering what he asked, As you said, It really is one of the worst methods, More as the blogspot is very limited, It may even be a good method.

  • 1

    Your answer is valid. I have commented for the user to have more information.. I will continue to ask for more information so we have more data on the service it has and see if there is another option.

  • 1

    Thank you, Sergio and Mega, for the information and knowledge transmitted. The solution presented by Mega worked and, although not the best solution, is the best for Blogger. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.