I am forced to change the URL of some pages of my site, but the problem I have is that if I do, I will lose the comments from comment box
Facebook.
Is there a way to change the URL so that the comments comment box
point to the new URL?
This is the code of comment box
:
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/es_ES/sdk.js#xfbml=1&version=v2.8&appId=93773124298xxxx";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-comments" data-href="https://www.example.com/" data-numposts="5"></div>
According to the Facebook documentation , the value of
href
/data-href
indicates:The default value (if you leave it empty) is the URL you are at, but if you specify a URL then it will be that URL. So what you would have to do is save the old URL and associate it somehow with the new one (eg in a database). And when you generate the Facebook code for the comments, put the value of the old URL.
For example, let's take the original page as this
http://misitio.com/blog.php?id=1234
and change it to look like this:http://misitio.com/blog/1234
. Then in the value ofdata-href
you will put the value of the original page instead of the new one: