I can see that bug in Drupal beta 2 as well as 4.7.4.

My server :

- Windows XP SP 2
- Apache 2.0.59
- PHP 5.1.4

In my Apache config file, I have

LoadModule rewrite_module modules/mod_rewrite.so

and :

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

and :

#The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs/2.0/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride All

Smart url is enabled and it works.

Except there is one major problem, which is resolved by disabling smart urls :

Let's say that in a story or page I have the following image :

<img src="files/pic.jpg" alt="Some pic" />

I am not using the Image Assist module here. I am just typing the HTML in the content of the story or page using "Full HTML" as filter.

In a List View, for example the front page, the picture will be displayed.

But in a Node view (when we open that story/page), or in Preview mode (when we edit it), the link is broken.

Reading the properties of the broken link image I see this :

File path in Node View :

http://localhost/drupal/node/files/pic.jpg

File path in Preview View :

http://localhost/drupal/node/4/files/pic.jpg

Why does smart url adds garbage such as "node" and the node id in the path of the image ?

Comments

Chill35’s picture

Title: Smart url breaks links to inline images in Single Node View and Preview » Clean URLs break links to inline images in Single Node View and Preview
heine’s picture

Status: Active » Closed (won't fix)

Because "files/some_files" is relative to the current page. Use a path relative to root, eg /files/some_file, or /myinstalldir/files/some_file".

http://www.extropia.com/tutorials/web_design/relative_absolute_links.html.

Chill35’s picture

Heine, using src=" /files/picture.jpg" breaks all the images in all views, including List View.

Why would it be different whether clean url are used or not ?
Why would a relative link work in one view and not in another ?

Thing is the content of a story or page is HTML. That HTML just ends up on the index.php page, in whatever view is asked of it.

I am not talking about an image I have uploaded using the upload module.

Chill35’s picture

I forgot to say that files/picture.jpg is relative to my root, where index.php is located.

Here is the absolute path for my file : http://localhost/drupal-4.7.4/files/pic.jpg

If I use this abolute path (the url) it works in all views, of course. (lol)

heine’s picture

Use a path relative to root [snip]

For your case a "path relative to root" would be /drupal/files/some_file.

Chill35’s picture

Yeah you're right.

If I use /drupal-4.7.4/files/pic.jpg it works.

But that makes me worried. When I move my Drupal installation on a remote server, all image links will break because the absolute path from the root (httdocs) will not be the same.

What do you recommend ?

Chill35’s picture

Heine,

Why does a relative path to index.php works so well for all views when clean URLs is disabled and it stops working when it is enabled ?

heine’s picture

Category: bug » support
Priority: Critical » Normal

Clean urls off:

location: /drupal/
link: files/my_file.png

Browser fetches /drupal/files/my_file.png .

location: /drupal/?q=node/4
link: files/my_file.png

Browser fetches /drupal/files/my_file.png because ?q=node/4 is an argument to the 'location' /drupal/.

Clean urls enabled:

location: /drupal/
link: files/my_file.png

Browser fetches /drupal/files/my_file.png .

location: /drupal/node/4
link: files/my_file.png

Browser tries to fetch /drupal/node/4/files/my_file.png because the current document location is /drupal/node/4.

Chill35’s picture

From a content displayed using php code, which php gives us the server path to index.php ?

I have something and it works, but it is aweful-looking :

The following always displays an image correctly, whatever its vue :

<?php
$index = 1;
$path = "";
while (arg($index)) {
$path .= "../";
$index++;
}
$path .="files/image.jpg";
echo '<img src="'.$path.'" alt="some picture" />';
?>
Chill35’s picture

Shorter :

<?php echo '<img src="'.base_path().'files/picture.jpg" alt="some picture" />'; ?>

That works too.

cog.rusty’s picture

Component: path.module » base system
Category: support » bug
Status: Closed (won't fix) » Active

Heine's description of the behavior was very clear. However I don't see a reason for this to be the intended behavior.

Why should the link be appended to the clean URL's node/4 'location'? What purpose could that ever serve? This is why I think it is a bug.

Chill35’s picture

Is there a quick dirty fix in .htaccess ?

  # Modify the RewriteBase if you are using Drupal in a subdirectory and
  # the rewrite rules are not working properly.
  RewriteBase /drupal-4.7.4

Or in sites/default/settings.php ?

$base_url = 'http://localhost/drupal-4.7.4'; // NO trailing slash!

I tried many, many things and it doesn't resolve the problem with clean URLs.

Chill35’s picture

This works :

http://localhost/drupal-4.7.4/node/1?q=node/3

It does open a view to node/3

???

cog.rusty’s picture

Version: 5.0-beta2 » 6.x-dev
Category: bug » feature

Changing status. The feature request is:

Make it possible for end users to enter html image links in nodes with php input disabled, which won't break when (a) the site is in a subdirectory, (b) clean URLs are enabled and (c) the site is moved.

Currently this is only possible with special image tags processed by an input filter.

Chill35’s picture

Category: feature » bug

I second that. There ought to be a way in core to do what CogRusty is describing.

I do believe that this is a bug, though.

Clean URLs are dealt with by Drupal.
It is Drupal that takes care of understanding clean URLs.
It is Drupal that creates ReWrite rules in an .htaccess file in the root of the Drupal folder so that when an HTTP request that is trying to retrieve such page as http://www.myWebSite.com/node/5 is received, that request is translated to please get us : http://www.myWebSite.com/index.php?q=node/5.
Since the path to the "files" folder is one set in Administer>settings>File System Settings by the user,
recorded as File system path,
i.e. since Drupal knows the path to that folder, Drupal should
add a special Rewrite rule to its own special Rewrite rules when clean URLs is enabled so that it can understand such path as : http://www.myWebSite.com/..../files/... to any file.
Hard-coding links to the web root folder is bad practice.
Relying strictly on contributed image "assist" modules to simply put images in content is way too restrictive.
A Rewrite Rule can be written by someone who understands regular expression well.

I don't want to get into any argument though. I am all for trying to find my own fix in life, so if someone changes the status back to feature request, rest assured I will stay out of it lol...

Regards,

Chill35’s picture

Version: 6.x-dev » 5.x-dev
cog.rusty’s picture

Oh, well, I was just being a realist.

mooffie’s picture

Chill35,

I think the img_relocator module can solve your problem:

http://blog.riff.org/2006_08_20_the_img_relocator_module_for_drupal

Chill35’s picture

That module is buggy.

gemini’s picture

I'm having the same problem in Drupal 5.1.

I'm using image_gallery and when I tuned pathauto to show images as [vocab]/[catatname]/[title] - suddenly my links to original images are broken because file path does not have the leading slash and appears as relevant path to the current (which is [vocab]/[catatname]/[title])... I can't believe that this can not be fixed in some (fairly) easy way...

dpearcefl’s picture

Status: Active » Closed (won't fix)

Considering the age of this issue with no responses and that D5 is unsupported, I am closing this issue.