46

Is the following URL valid?

http://www.example.com/module.php/lib/lib.php

According to https://www.rfc-editor.org/rfc/rfc1738 section the hpath element of an URL can not contain a '.' (period). There is in the above case a '.' after "module" which is not allowed according to RFC1738.

Am I reading the RFC wrong or is this RFC succeed by another RFC? Some other RFC's allows '.' in URLs (https://www.rfc-editor.org/rfc/rfc1808).

Community
  • 1
  • 1
Moffe
  • 573
  • 1
  • 4
  • 7

4 Answers4

61

I don't see where RFC1738 disallows periods (.) in URLs. Here are some excerpts from there:

hpath          = hsegment *[ "/" hsegment ]
hsegment       = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
uchar          = unreserved | escape
unreserved     = alpha | digit | safe | extra
safe           = "$" | "-" | "_" | "." | "+"

So the answer to your question is: Yes, http://www.example.com/module.php/lib/lib.php is a valid URL.

Adam Batkin
  • 51,711
  • 9
  • 123
  • 115
18

As others have noted, periods are allowed in URLs, but be careful. If a single or double period is used in part of a URL's path, the browser will treat it as a change in the path, and you may not get the behavior you want.

For example:

  • www.example.com/foo/./ redirects to www.example.com/foo/
  • www.example.com/foo/../ redirects to www.example.com/

Whereas the following will not redirect:

  • www.example.com/foo/bar.biz/
  • www.example.com/foo/..biz/
  • www.example.com/foo/biz../
speedplane
  • 15,673
  • 16
  • 86
  • 138
  • Can you give an example of a browser which makes this interpretation and does this kind of automatic rewrite? I am aware that certain web _servers_ will respond to HTTP requests with these redirects, but not of browsers which would rewrite these URLs themselves. – Brandon Rhodes Sep 19 '22 at 19:18
  • Load up chrome, open the network tab in dev tools, and navigate to `http://www.example.com/foo/../`. If you look in the network tab, you'll notice that the request was actually made to `http://www.example.com/`, without any server redirection. – speedplane Oct 22 '22 at 14:11
11

Periods are allowed. See section "2.3 Unreserved Characters" in this document: https://www.rfc-editor.org/rfc/rfc3986

"Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde".

Community
  • 1
  • 1
Greg Burdett
  • 191
  • 2
  • 6
2

Nothing wrong with a period in a url. If you look at the makeup in the grammar in the link you provided a period is mentioned via the 'safe' group, which is included via uchar a

Ignore my answer, Adams is better

vickirk
  • 3,979
  • 2
  • 22
  • 37