0

I'm using the migrate (7.x-2.x-dev) module to import a node(s) from static HTMLs to Drupal 7, and I want to set the path the same as the original directory/filename. I have defined in my migration class as follows,

$this->addFieldMapping('path', 'filename');
$this->addFieldMapping('pathauto')->defaultValue(0);

and it seems to be working - when I open the imported node in the edit mode, I see the correct path in the path field, and the Generate automatic URL alias checkbox is unchecked.

However, the path is not working. Say, when the path is set to be info/legacy.html, and the node is 21,

http://localhost/node/21  

is fine, whereas

http://localhost/info/legacy.html

returns 404 (Page not found).

In fact, the node is not listed in the Content page /admin/content either. I found the node number (21 in this case) by browsing directly the SQL database (the entry of the node in the database looks no different from other nodes).

Everything else looks fine, I mean, all the fields related to the node are imported as I intend. But the above-mentioned 2 points are weird...

Why is it so, and how can I achieve the above? Any idea?

1 Answer 1

0

Actually, I have just found out it was due to the i18n setting of the node and site. The language of the node was set to be ja (Japanese), correctly. Probably because of that,

http://localhost/info/legacy.html

does not work (HTTP 404), but

http://localhost/ja/info/legacy.html

does display the node imported.

Similarly, the Content manager does not display the node in the default-language mode (English) /admin/content, however it does display the newly imported node in Japanese /ja/admin/content. I should note I allow all the URL (Path prefix), Session, User, Browser in the language configuration (/admin/config/regional/language/configure) in my environment.

My browser's HTTP request, when I test, is

"Accept-language": ja

So, I expected when I opened

http://localhost/info/legacy.html

it would open the node in Japanese, following the browser's request, as opposed to 404, but it does not, apparently.

Hmm, I guess it is likely my understanding of the i18n handling in Drupal is not sufficient. Anyway, I think this can be solved with the redirection module in Drupal, after investigating and finding out how to set it up during migration. I didn't want the default URI to be something like node/21, but if it is ja/info/legacy.html, I am fine with it, as long as the redirection works.

[Edit: 2014-10-06]
I have figured out why. In my i18n setting of Drupal, URI-path-prefix is checked and is given the highest priority, where English is default with its language-code for path-prefix being undefined. Hence,

http://localhost/info/legacy.html

is the English version of the content, which does not exist. When I define the language-code of English (en) for path-prefix, then the access to the URI brings up the Japanese version, if my browser's preferred language is Japanese (and the i18n of the site is configured to accept the browser's preferred language at the lowest priority), because the URI is not any more specific for the English version.

Another note is the redirection module works only when redirecting to a node URI [or path without the language-code prefix (added on 2014-10-11)]. The redirection to, for example,
/ja/info/legacy.html
does not work well, as it can bring up the path of

http://localhost/ja/ja/info/legacy.html

in some cases.

[Edit: 2014-10-11]
The whole point (and much more) is covered and summarised in the document published at drupal.org: https://www.drupal.org/node/2354755

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.