Reputation: 9808
I'm always confuse whether I should add a trailing slash at the end of a path, and often mix it up, leading to some file no found. Example with drupal:
$base_theme = '/sites/all/themes/myTheme/';
or
$base_theme = '/sites/all/themes/myTheme';
The image path could extend the base theme:
$base_image = $base_theme.'images/';
or
$base_image = $base_theme.'/images';
Is there any convention? Or I can pick which one I prefer?
I would choose to finish all path with a trailing slash since too many slash is better than no slash.
Upvotes: 22
Views: 7043
Reputation: 21694
TL;DR: There's no real convention. Trailing slash would be the more globally easy to recognize format. The important thing is that you're consistent through your design and that you convey your usage clearly.
There's no real convention; but there are considerations to make.
example.com/home/
VS example.com/style.css
).http://example.com/styles//myfile.css
) but will not break the file link. Forgetting a slash will: http://example.com/stylesmyfile.css
, however the behavior might be confusing for query strings: http://example.com/thread?id=1
VS http://example.com/thread/?id=1
<- the result really depends on how you handle your .htaccess
.$baseURL . '/path.php'
than $baseURL . 'path.php'
Upvotes: 26