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 AllSmart 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
Comment #1
Chill35 commentedComment #2
heine commentedBecause "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.
Comment #3
Chill35 commentedHeine, 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.
Comment #4
Chill35 commentedI 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)
Comment #5
heine commentedFor your case a "path relative to root" would be /drupal/files/some_file.
Comment #6
Chill35 commentedYeah you're right.
If I use
/drupal-4.7.4/files/pic.jpgit 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 ?
Comment #7
Chill35 commentedHeine,
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 ?
Comment #8
heine commentedClean 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.
Comment #9
Chill35 commentedFrom 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 :
Comment #10
Chill35 commentedShorter :
<?php echo '<img src="'.base_path().'files/picture.jpg" alt="some picture" />'; ?>That works too.
Comment #11
cog.rusty commentedHeine'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.
Comment #12
Chill35 commentedIs there a quick dirty fix in .htaccess ?
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.
Comment #13
Chill35 commentedThis works :
http://localhost/drupal-4.7.4/node/1?q=node/3It does open a view to node/3
???
Comment #14
cog.rusty commentedChanging 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.
Comment #15
Chill35 commentedI 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,
Comment #16
Chill35 commentedComment #17
cog.rusty commentedOh, well, I was just being a realist.
Comment #18
mooffie commentedChill35,
I think the img_relocator module can solve your problem:
http://blog.riff.org/2006_08_20_the_img_relocator_module_for_drupal
Comment #19
Chill35 commentedThat module is buggy.
Comment #20
gemini commentedI'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...
Comment #21
dpearcefl commentedConsidering the age of this issue with no responses and that D5 is unsupported, I am closing this issue.