drupal 7、路径和URL工作不正常

drupal 7、路径和URL工作不正常,url,drupal-7,Url,Drupal 7,我正在本地主机上开发一个基于drupal的网站。我对URL有问题 对于这样的url: http://localhost:81/my_website/library 我必须以以下方式输出图像src: <img src="<?php print $directory; ?>/image/header/headerR.png"/> <img src="../<?php print $directory; ?>/image/header/headerR.pn

我正在本地主机上开发一个基于drupal的网站。我对URL有问题

对于这样的url:

http://localhost:81/my_website/library
我必须以以下方式输出图像src:

<img src="<?php print $directory; ?>/image/header/headerR.png"/>
<img src="../<?php print $directory; ?>/image/header/headerR.png"/>
我必须以以下方式输出图像src:

<img src="<?php print $directory; ?>/image/header/headerR.png"/>
<img src="../<?php print $directory; ?>/image/header/headerR.png"/>
我的意思是它一定是指父母。我的网站有可插入的上下文过滤器
在library/之后。是否有处理此类问题的通用解决方案?

如果要将图像直接打印到html,则必须使用非相对路径移动到其他目录。必须始终以/开始映像路径,以便映像相对于域(在本例中为localhost)。范例

<img src="/<?=$whatever; ?>" />
根据需要使用其中任何一种。
希望能有所帮助。

只使用相对路径,将主题相关图像放入主题文件夹

假设您的主题被命名为YOURTHEME 当你这样做的时候 它应该从中加载图像http://localhost:81/sites/all/themes/YOURTHEME/iamge/header/headerR.png

但如果您需要从不同于主题目录加载图像,则需要使用CDN模块
您还可以轻松地从其他服务器加载图像,这在处理本地开发人员和从生产服务器获取图像时非常有用

尝试使用/image/header/headerR.png/>它应该可以在大多数D7环境中工作。base_path从settings.php中提取基本路径(如果已设置)。path_to_主题将路径拉到默认主题,您也可以通过特定主题。