The best convention is whether or not you intend the path to be relative or absolute. Generally, a leading '/' specifies an absolute path, from the root of a file system, or the root of a website.
Take an example CSS file, located at at mysite.com/files/css/info.css
...
background-image:url('/bg.png'); /* absolute - use mysite.com/bg.png */
background-image:url('bg.png'); /* relative to info.css - use mysite.com/files/css/bg.png */
...
In your own code, when you have an option of ommitting or including a leading slash, you can follow a similar convention:
<?php
// $uri - the relative/absolute uri to link to, ie /posts or 'show/id'
// $text - the text link
function link_to($uri, $text) {
if ($uri[0] == '/') {
// assume absolute
$href = $uri;
} else {
// assume relative to current uri; remove last segment and replace
$uri_segments = get_uri_segments();
array_pop($uri_segments);
array_push($uri_segments, $uri);
$href = implode('/', $uri_segments);
}
return "<a href=\"$href\">$text</a>";
}
//
// elsewhere, assuming current URL is 'myself.com/users'
//
// relative link to 'create'
link_to("create", "Show User"); // mysite.com/users/create
// absolute link to '/products'
link_to("/products", "Products"); // mysite.com/products
?>