Is it better to use in the content, e.g. stories, articles etc. relative links like

drupal/my-pages
../drupal/my-pages
../../../drupal/my-pages

or relative absolute ones like

/drupal/my-pages
/drupal/other-my-pages
/drupal/more-pages/other-my-pages

Nice greetings, Dirk.

Comments

dman’s picture

I'm afraid that root-relative ones (relative absolute ) are the only way to work within Drupal. With aliases and views and teasers being able to show up almost anywhere, true relative links have a very limited chance of surviving.
You may not need it yet, or think that your structure can handle relatives ... but relative links are fragile. Use root-relative.

I'd like links to be relative and portable ... but that can't fit with a flat data-driven CMS.
There are bigger issues (like you hard-coding references to an absolute drupal-pathname) but I don't know the best solution to that problem. maybe a link rewriter like pathologic.

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

Dirki’s picture

Many thanks dman.

I'm afraid that root-relative ones (relative absolute ) are the only way to work within Drupal.

Both kind of links - as it seems now to me and I am not using the modules "Aliases" and "Views" and "Teasers" - do work properly, there seems to be any difference untill now. But the problems, malfunction by using relative links will occur when I start to use these modules, respectivly modules like these at the latest?

A disadvantage - not that important - when using relative absolute links could be if one move the folder Drupal is installed in to another level, you would have to adapt the paths of all links within Drupal. That is what you mean by "portable", isn`t it?

Okay, so then I will change all relative links to root-relative ones like "/drupal/my-pages", "/drupal/other-my-pages", now.

What means a "flat data-driven CMS".

Thanks, again, nice greetings, Dirk.

----------------------------------------------------
http://www.galerie-der-fotos.de

dman’s picture

Yeah, any module or feature which shows nodes or parts of nodes in any place except its node/n location will cause trouble for relative links.
Yes, I know that moving sites with root-relative links is a pain, which is why I wish there was an easy better solution.
By "flat data driven" I meant that Drupal places its content in one, unstructured place. Pages don't have any real location or heirarchy apart from what is patched on using other tools. It's fine, and it works, but it's a different way to think about it than a structured filesystem which URLs traditionally represented.

.dan.
if you are asking a question you think should be documented, please provide a link to the handbook where you think the answer should be found.
| http://www.coders.co.nz/ |

Dirki’s picture

Okay, thank you very much, dman,

Very good to know that all, especially as I would have used relative links further on otherwise, I guess, causing (may be hard to identifying) problems some time and some easily to avoid work.

I assume, actually it is usually very seldom to move the Drupal folder.

By the way, without the module "pathauto" it is not possible (according to my tries) to create readable URLs - e.g. /drupal/a-page#anchor instead of drupal/node/23#anchor - leading to an anchor, isn`t it?

Many thanks, again, nice greetings, Dirk.

----------------------------------------------------
http://www.galerie-der-fotos.de

hoopslave’s picture

I don't know HTML or Drupal very well. It's probably a complete newbie question, but I'm trying to add an HTML link (via FCKeditor) within a Block and can't get the link to work properly. It shows "Object Not Found" - Apache error because the URL is jumping past my Drupal folder. The actual URL for the page I am trying to reach is http://localhost/drupal-boys/become_a_blog_writer, but it is processing http://localhost/become_a_blog_writer.

Jztinfinity’s picture

I've actually had to deal with the same problem, coupled with using the domain access module which meant that the root domain of a url changed form node to node. My solution was to wrap a function around this query
SELECT CONCAT(domain.scheme,'://',domain.sitename,'/',url_alias.dst)
FROM url_alias
INNER JOIN node ON (CONCAT('node/',node.nid)=url_alias.src)
INNER JOIN domain_source ON (domain_source.nid=node.nid)
INNER JOIN domain ON (domain.domain_id=domain_source.domain_id)
WHERE node.nid=%nid

This should give you the absolute url for any give nid.
(If you don't have multiple domains, use
SELECT CONCAT(%sitename,'/',url_alias.dst)
FROM url_alias
INNER JOIN node ON (CONCAT('node/',node.nid)=url_alias.src)
INNER JOIN domain_source ON (domain_source.nid=node.nid)
INNER JOIN domain ON (domain.domain_id=domain_source.domain_id)
WHERE node.nid=%nid)

Still, in general for drupal I think relative urls are better than absolute ones and node/#nid urls are better than url_aliases because this way if you change the subdomain or url_alias of a node, you won't have to worry about setting up a redirect or updating all your links