# Org-mode don't change relative URLs

How can I prevent Org from exporting [[/][site root]] as <a href="file:///">site root</a>?

• What would you like it to export instead? – nanny Mar 4 '15 at 13:52
• @nanny just the /. – wvxvw Mar 4 '15 at 13:57
• Also, FYI, / is not a relative path. Relative paths don't start with a slash. – nanny Mar 4 '15 at 13:59
• @nanny why not? Anyways, even if you think that only those which begin with a dot (or a URI Component character) are, the question is still the same. – wvxvw Mar 4 '15 at 14:12
• My mistake, it is a relative url (but not a relative path, as in file path, I confused the two). I found something that may help: orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html – nanny Mar 4 '15 at 14:23

OK, since I didn't find a ready-made one, I decided to roll my own. This doesn't seem to be difficult at all, so here goes:

(defun wvxvw/export-rel-url (path desc format)
(cl-case format
(html (format "<a href=\"%s\">%s</a>" path (or desc path)))
(latex (format "\href{%s}{%s}" path (or desc path)))
(otherwise path)))



Usage example: [[rel:./foo/bar][foo bar]] translates into HTML: <a href="./foo/bar">foo bar</a>.

The most important part is the org-add-link-type - this allows to specify the way to export the link. This code isn't universal, since it doesn't support even all the back-ends enabled by Org by default, but it should be obvious how to add more.

Starting with Orgmode 9.0 the function org-add-link-type is deprecated. One should use org-link-set-parameters instead.

There follows the equivalent Elisp code for Orgmode 9.0. Note that the only change is the replacement of org-add-link-type with org-link-set-parameters. The function wvxvw/export-rel-url is unchanged. It is only cited here to ease copy-paste.

(defun wvxvw/export-rel-url (path desc format)
(cl-case format
(html (format "<a href=\"%s\">%s</a>" path (or desc path)))
(latex (format "\href{%s}{%s}" path (or desc path)))
(otherwise path)))