For SEO reasons I'd like the urls to be preserved on the Drupal site. Does this module do that?

Thanks,

Shai

Comments

ParisLiakos’s picture

Version: 7.x-1.0-alpha4 » 7.x-2.x-dev

Right now, nope.. i will try to get this functionality to 7.x-2.x though (will take a while)
till then, patches are welcomed

ParisLiakos’s picture

Category: support » feature
ParisLiakos’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Active » Closed (won't fix)

Actually this doesn't make sense for SEO since the domain name changes.

After import you could just have pathauto do this job for you creating a human-friendly pattern for the content type you imported your posts to and then updating existing content url aliases

attheshow’s picture

Version: 7.x-2.x-dev » 7.x-1.0-beta3

I might try to work on this. Basically I need it to work like this for SEO purposes:

http://example.blogspot.com/post.html
http://newblogurl.example.com/post.html

I'm going to do a meta refresh from the blogger template to have the user forwarded over to the same URL at the new domain. That means I need this module to recreate the post at the same address on the new domain.

attheshow’s picture

I coded a little custom module for my site that takes advantage of the existing HOOK_blogger_importer_node. Basically the code of the module file looks like this:

function MYMODULE_blogger_importer_node($op, $node, $post) {
  if ($op == 'presave') {
    $new_path = $post['url'];
    $new_path = str_ireplace('http://example.blogspot.com/', '', $new_path);
    $node->path = array('alias' => $new_path);
  }
  else {
    drupal_set_message('hello! no presave.');
  }
}

If you do this sort of thing, the import process should bring over the legacy URLs for you during the node save process. Just be sure to replace "example.blogspot.com" in the code above the the base URL of your old Blogger blog!

attheshow’s picture

Status: Active » Closed (fixed)

In case anyone else needs to do this: It also looks like if you have the Pathauto module turned on in D7, it monkeys with the URL aliases that you're trying to preserve. I recommend temporarily turning Pathauto off while you do the Blogger import, then turn it back on.

elijah lynn’s picture

Status: Closed (fixed) » Active

Thanks for the code snippet attheshow and everyone else for the module!

I am having trouble getting this to work, I put it in a custom module and I don't get any errors but I don't have any redirects on import. I did replace my domain and the hook name etc. I have redirect and global_redirect enabled. Do I need to have another module to make this work?

Thanks

Update: Btw, I am doing the same thing you are doing with the redirects to a new domain. This really should be in the main module as it is best SEO practice. Maybe when I am more up to speed on this I can contribute something back that helps get this in.

elijah lynn’s picture

Okay, I see now that it doesn't do redirects, which is what I want, but I cannot even get it to make the paths. I also am not getting the "'hello! no presave.'" dsm.

elijah lynn’s picture

I am not sure the hook is working. I set a breakpoint in xdebug and it just flies right on by.

Here is my module (blog_path), note that I tried with and without the reference on $node, the documentation in README.txt says to use a reference:

<?php

function blog_path_blogger_importer_node($op, &$node, $post) {

  if ($op == 'presave') {
    $new_path = $post['url'];
    $new_path = str_ireplace('http://elijahlynn.blogspot.com/', '', $new_path);
    $node->path = array('alias' => $new_path);
  }
  else {
    drupal_set_message('hello! no presave.');
  }
}

Edit: Also, in batch.nodes.inc on line 247 it says:

      // DEFINE A HOOK FOR OTHER MODULES TO ADD/MODIFY THE NEW NODE CONTENTS OR OTHERWISE ACT ON THEM
      // invoke hook as HOOK_blogger_importer_node_alter(&$node, $post, $op)
      // - only $op implemented now is 'presave' but might want more later
      // - ignores return value
      // example usage: map the original URL of each post to a redirect handler
      $op = 'presave';
      drupal_alter('blogger_importer_node', $node, $post, $op);

The comment has the order different for the parameters and also _alter appended. Can someone unconfuse me?

Thanks!

ParisLiakos’s picture

MYMODULE_blogger_importer_node_alter($node, $post, $op) {
  if ($op == 'presave') {
    $new_path = $post['url'];
    $new_path = str_ireplace('http://elijahlynn.blogspot.com/', '', $new_path);
    $node->path = array('alias' => $new_path);
  }
  else {
    drupal_set_message('hello! no presave.');
  }
}

This is the new usage of this

elijah lynn’s picture

Coincidentally, that is what I was trying after reading that. But still nothing is happening on import, nor am I able to get a breakpoint to fire. However, there is one difference. I am prefacing with function: function blog_path_blogger_importer_node($node, $post, $op).

Is that intentional?

However, if I mess up the code in the module it will throw a PHP error on a white page.

ParisLiakos’s picture

ah sorry missed function.
it should be in you case:

function blog_path_blogger_importer_node_alter($node, $post, $op) {
  // do stuff
}
ParisLiakos’s picture

StatusFileSize
new474 bytes

Posted the module here. if you dont have devel module installed, remove the dpm lines

ParisLiakos’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev

Can someone please expose two textfields for this module so this one can be included in next blogger_importer release?
Right now blog name is hardcoded inside this function, if we can get this sorted this is ready to go, just tested myself works great

elijah lynn’s picture

Version: 7.x-2.x-dev » 7.x-1.0-beta3
Status: Closed (won't fix) » Active

Thank you very much rootatwc!

It turns out that I enabled your module and it works!!!

It also turns out that I had not even enabled my module. I had done it so many times after doing a database restore that the last time I did it with the right HOOK implementation I forgot to enable the module.

Sorry for wasting an hour of your life.

At the very least I will submit a patch to have the README.txt reflect the new HOOK.

Also for those who want to test if this works, if you install Drush and Devel you can run drush hook blogger_importer_node_alter and it should return the name of the module (cmdule).

elijah lynn’s picture

Exposing the text fields is a bit over my head right now but if someone wants to setup a time to mentor me on how to do that on IRC I would be happy to give it a go.

elijah lynn’s picture

We also need to get the template file that needs to be enabled on blogger to do the new canonical name that redirects to the new domain, that is an associated but separate ticket. There is some example text here on doing a Blogger to Wordpress migration while retaining Google Rank (with canonical) - http://www.labnol.org/internet/switch-from-blogger-to-wordpress/9707/

edit: I just made a new issue for this here --> http://drupal.org/node/1796970

pazzaglia’s picture

I'm also interested in the feature Blogger to durpal maintaining the URL. In a couple of months I would like to move my sizable blog to a this platform.

Perhaps, what the original requester did not mention - or at least is MY case - is that I have a Blogger Blog with custom domain. So all of my posts are linked from google (and eachother) using:

http://www.mysite.com/2012/11/postname.html

I would like to import the XML file and re-create the same file structure OR have some way to automatically generate redirects to the new php pages - my site has over 200 pages (thousands of links from other sites to individual pages) so it's just impossible to do this by hand in the three days it will take to transfer my domain from google to a web host running Durpal.

The Canonical tag would be the same kind of individual effort for each post, and would only work if I kept the blog running on the domain name on blogger and not to a web host running Durpal.

Thanks for all of you work on this so far, and I hope you can help me get off Blogger in a painless way!!

stratos’s picture

Here is my module (blog_path), note that I tried with and without the reference on $node, the documentation in README.txt says to use a reference:

Could you explain me clearly, what to do with that code? Should I create a new own module with it? How?

Thanks for answer for my stupid question.

haleagar’s picture

Issue summary: View changes
StatusFileSize
new1.35 KB

OK as requested I exposed the old URL to strip out on a configuration page so you could use this module, preserving paths with no code edits.

haleagar’s picture

StatusFileSize
new1.53 KB
haleagar’s picture

added further option to have two source urls, and handle with and without the www.

cgmonroe’s picture

FYI - The code in #21 has a few bugs in it.

- Schema Removed if no alt domain name is specified

If you do not specify and alternate URL in the set up page, all URLs in the body text will have the http:// or https:// prefix stripped. This is because the default value of '' creates a string replace for "http://" only.

Quick fix is to make sure to add an alternate URL whether you need it or not.

Longs term fix would be to check for a value before doing the replace calls in the code.

- Path not preserved if pathauto module is enabled.

Fix is to have the following after the alias is set.

      $node->path['pathauto'] = 0; // Required only if Pathauto is enabled.

- Undefined index: url in blogger_preserve_path_blogger_importer_node_alter() (line 23 of blogger_preserve_path.module)