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.
Historically, a trailing slash marked a directory and a URL without a trailing slash at the end used to mean that the URL was a file. Today, however, trailing slashes are purely conventional, and Google does not care whether you use them; as long as you're consistent.
When using APPEND_SLASH , if they accidently sent it without trailing slash, and your urlconf is WITH a trailing slash they would get an exception about data lose when redirecting POST requests.
REST API's should not expect a trailing slash and should not include them in the links that they provide to clients. However, every character within a URI counts toward a resource's unique identity. Two different URIs map to two different resources.
"If it ends with a slash, it's a directory.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With