4

I am seeing a great number of errors in our log files related to the use of the dot-slash "./" on the href attribute of the anchor tag. It only happens when the hit comes from a java client.

HTML DOCUMENT
<a href="./myPage.php">Link to a dot-slash file</a>

ACCESS LOG ENTRY
my.domain.com 123.456.789.012 - - [26/Jan/2010:14:17:15 -0500] "GET /legal/./myPage.php HTTP/1.1" 200 5295 "-" "Java/1.6.0_14"

ERROR LOG ENTRY
[Tue Jan 26 14:17:15 2010] [error] [client 123.456.789.012] request failed: erroneous characters after protocol string: GET /legal/\\" + gaJsHost + \\"google-analytics.com/ga.js HTTP/1.1

Is it a best practice to use or not use the dot-slash?

Veger
  • 37,240
  • 11
  • 105
  • 116
H. Ferrence
  • 7,906
  • 31
  • 98
  • 161

1 Answers1

7

As far as I know the dot-slash is only used in *nix and not "on the internet". I'd advise not using it, also because (afaik)

href="./example.php"

is pretty much the same as

href="example.php"
Niels Bom
  • 8,728
  • 11
  • 46
  • 62
  • Thanks Niels. You are correct in that the "./" in a href yields the same result as not using the "./". – H. Ferrence Jan 27 '10 at 17:33
  • 1
    But `href="./"` is different from `href="/"`. What if I want to link to the current directory's root rather than the site's root? – showdev Feb 06 '13 at 23:11
  • @showdev, so what "document" do you link to in the current directory? I mean, you want to point to a webpage (www.example.com/contact) right? Not to a "namespace" in your website structure. Could you give a concrete example? Maybe open a new question? – Niels Bom Feb 07 '13 at 16:10
  • 1
    @NielsBorn I was pointing out that `./` can be used to link to the current directory root (on the internet). For example, if I have a page at `example.com/beta1/somepage.php` and I want to link to `example.com/beta1/(index.php)` from `somepage.php`, I'd use `herf="./"`. – showdev Feb 07 '13 at 17:26
  • @NielsBom it is perfectly valid to use `.` and `..` in `A`'s `href`attribute, or generally in URIs: http://www.ietf.org/rfc/rfc2396.txt . `./` is a good way to refer the index page of the current directory as well as e.g. `./../` for that of the parent directory. However, I agree: it does not make any difference when explicitely referring to a file name. – peterp May 13 '13 at 13:10