开发者

Slashes after directory-names in various languages and configurations

The question is really simple: should a path to a directory always contain a slash at the end?

say开发者_StackOverflow社区: /path/to/directory/ over /path/to/directory.

Linux/Unix seem to accept both. Most applications and libraries on linux follow this. e.g. a <Directory /home/someproject/foo/code> works just fine.

In programming, say PHP I can do a dir on both directories with a slash-at-the-end. and those without. PHP's documentation has examples that omit the / http://www.php.net/manual/en/class.dir.php

In Ruby the same: I can use /path/to/dir/ and /path/to/dir in Dir?

What is the "best practice"? Is there a performance-penalty when using one of both? Are there edge-cases where both work different, or one of both will break?


I use the trailing slash for consistency. If I am building a dynamic path/name, I like to see the trailing slash to indicate I am done any construction of that part of the path. This coincides with my decision to also use trailing slashes for web locations. Some people's thoughts can found at http://www.fiftyfoureleven.com/weblog/search-engines/trailing-slashes-best-practice

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜