迁移到新域

发布于 2024-09-11 17:27:51 字数 546 浏览 3 评论 0原文

我正在 mydomain.com/drupalsite 上的 drupal 6 站点上工作,设计者在其中放置了许多硬编码的图像路径,例如 mydomain.com/drupalsite/img 中的自定义 img 文件夹。因此,很多网站都使用 /drupalsite/img/myimg1.png 的链接。

问题是——该网站最终将通过将 Finaldomain.com 指向 mydomain.com/drupalsite 转移到 Finaldomain.com。因此,现在像 /drupalsite/img/myimg1.png 这样的路径将解析为 Finaldomain.com/drupalsite/img/myimg1.png,而不是应该是 Finaldomain.com/img/myimg1.png。 Finaldomain.com 站点必须指向该子目录,以便它访问 index.php。

我的第一直觉是使用 .htaccess 文件将 /drupalsite 替换为“”,但我已经尝试了大约十几种不同的解决方案,但它们都不起作用。我的解决方案是使用一些 ln -s 链接,但我真的不喜欢它:) tia

Andrew

I'm working on a drupal 6 site at mydomain.com/drupalsite, and the designer has put a lot of hardcoded image paths in there, for instance a custom img folder in mydomain.com/drupalsite/img. So a lot of the site uses links to /drupalsite/img/myimg1.png.

Here's the problem -- the site is eventually moving to finaldomain.com, via pointing finaldomain.com to mydomain.com/drupalsite. So now paths like /drupalsite/img/myimg1.png will resolve to finaldomain.com/drupalsite/img/myimg1.png, instead of what should be finaldomain.com/img/myimg1.png. The finaldomain.com site has to point to that subdirectory so it hits the index.php.

My first instinct is to use an .htaccess file to replace the /drupalsite with "", but I've tried about a dozen different solutions and they haven't worked. My hack of a solution was to use some ln -s links but I really don't like it :) tia

Andrew

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何处潇湘 2024-09-18 17:27:51

事后看来,最好的方法是确保人们使用 Drupal 函数来创建所有链接:

  • l(即字母 L)
  • drupal_get_path()
  • base_path()< /code>

l() 函数负责处理基本路径问题,并提供系统的方法来定义 URL。使用诸如 theme_image() 之类的东西加上 l() 函数肯定会获胜。如果您必须编写自己的 标记并在 theme_image() 等主题函数中使用,请使用上面的第二个和第三个函数。

但对于您目前的情况:

关于安迪的解决方案,如果您可以将更改限制在您知道链接所在的某些数据库字段,那就更好了。

因此,编写一个查询来选择所有这些字段(例如所有正文字段):

$my_query = db_query("SELECT vid, body FROM {node_revisions}");

例如,这将获取 node_revisions 表中的每个 body 字段,因此即使您的旧修订版将有适当的链接。

然后运行这些结果,对每个结果执行 str_replace() ,然后写回更改:

while($node = db_fetch_object($my_query)) {
  $new_body = str_replace('what you have', 'what you want', $node->body);
  db_query("UPDATE {node_revisions} SET body = '%s' WHERE vid = %d", $new_body, $node->vid);
}

我显然会首先在一条记录上尝试它,以确保您的代码按预期运行(只需添加一个例如,WHERE vid = 5,将其范围缩小到一个版本)。此外,我没有利用node_loadnode_save,它们更适合正确加载和保存节点,从而提供更通用的解决方案(供您替换)块中的文本等)。

对于您的文件,我建议使用一个很好的 ol' sed 命令,方法是在“sites”文件夹中运行类似以下内容:

find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;

Nabbed that 从这里,所以请查看该网站以获得更多解释。如果您要使用路径,则需要在您的 sed 命令版本中转义路径的 /,或者使用不同的 < code>sed 分隔符(即您可以编写 s#string1#string2# 而不是 s/string1/string2/,因此您可以编写 s #/drupalsite/img/#/img# 而不是 s/\/drupalsite\/img\//\/img/ :-)。另请参阅 Drupal 手册页面以获取快速 sed 命令:http://drupal.org/node /128513

有点混乱,这就是为什么我尝试预先强制使用正确的函数。但是,如果您希望主题创建 Drupal 内容,但又不想让他们访问“PHP Filter”输入格式,或者他们根本不了解 PHP,那么这就很困难。正确的 Drupal 主题,在基本 HTML/CSS 工作之后的任何时候,都需要了解 PHP 和 Drupal 的主题相关功能。

The best method, in hindsight, is to ensure folks use Drupal functions to make all links:

  • l (that's the letter L)
  • drupal_get_path()
  • base_path()

The l() function takes care of base path worries, and provides a systematic way to define your URL's. Using things like theme_image() plus the l() function are a sure win. Use the second and third functions above if you have to write your own <a> tags and for use inside theme functions like theme_image().

But for your current situation:

As regards Andy's solution, it would be better if you could limit your changes to certain database fields where you know the links are located.

So write a query to select all those fields (e.g. all body fields):

$my_query = db_query("SELECT vid, body FROM {node_revisions}");

This, for example, will get you every body field in the node_revisions table, so even your old revisions would have proper links.

Then run through those results, do str_replace() on each, and then write the changes back:

while($node = db_fetch_object($my_query)) {
  $new_body = str_replace('what you have', 'what you want', $node->body);
  db_query("UPDATE {node_revisions} SET body = '%s' WHERE vid = %d", $new_body, $node->vid);
}

I'd obviously try it on one record first, to make sure your code behaves as intended (just add a WHERE vid = 5, for example, to narrow it down to one revision). Furthermore, I haven't taken advantage of node_load and node_save, which are better for loading and saving nodes properly, so as to provide a more general solution (for you to replace text in blocks, etc.).

For your files, I'd suggest a good ol' sed command, by running something like the following from within your "sites" folder:

find ./ -type f -exec sed -i ’s/string1/string2/’ {} \;

Nabbed that from here, so take a look on that site for more explanation. If you're going to be working with paths, you'll either need to escape the / of the paths in your version of the sed command, or use a different sed separator (i.e. you can write s#string1#string2# instead of s/string1/string2/, so you could write s#/drupalsite/img/#/img# instead of s/\/drupalsite\/img\//\/img/ :-). See also Drupal handbook page for quick sed commands: http://drupal.org/node/128513.

A bit of a mess, which is why I try to enforce using the proper functions up front. But this is difficult if you want themers to create Drupal content but you don't want to give them access to the "PHP Filter" input format, or they simply don't know PHP. Proper Drupal theming, at any point past basic HTML/CSS work, requires a knowledge of PHP and Drupal's theme-related functions.

辞取 2024-09-18 17:27:51

我之前已经通过获取完整的数据库转储,在文本编辑器中打开它,并对路径进行全局搜索和替换来完成此操作。然后在新主机上加载修改后的转储文件,它将具有正确的路径。

I've done this before by taking a full database dump, opening it in a text editor, and doing a global search and replace on the paths. Then on the new host, load the modified dump file, and it will have the correct paths in.

脸赞 2024-09-18 17:27:51

你可以尝试Pathologic,它应该能够纠正这样的路径。

You could try Pathologic, it should be able to correct paths like this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文