[OT] absolute vs. relative URI
invalid at invalid.invalid
Fri Jan 23 15:47:04 CET 2015
I'm maintaining a web app were the original author(s) went to a little
bit of trouble to always use absolute URIs in links in the pages.
First, the code checks the port number the server is listening on and
extrapolates the protocol being used (http or https). Then it grabs
the server value from the request and sets a more-or-less global
variable 'wwwroot' something like this:
if port in (443,8433)
proto = 'https'
proto = 'http'
wwwroot = "%s://%s/" % (proto,server)
If the user orignally entered a URL with the literal IP address
10.0.0.99, then wwwroot ends up with a value of "http://10.0.0.99/"
Then, throughout the rest of the code that variable is used so that
all links are absolute (including protocol, host, and absolute path):
"<a src='%sWhatever>Whatever</a>" % wwwroot
Why do they go to the extra work of constructing the value for wwwroot
and then inserting it later?
I'm not an HTLM/HTTP guru, but I've tinkered with web pages for 20+
years, and for links within sites, I've always used links either
relative to the current location or an absolute _path_ relative to the
I've never had any problems with links like that. Is there some case
where that doesn't work right and I've just been stupidly lucky?
Grant Edwards grant.b.edwards Yow! It don't mean a
at THING if you ain't got
gmail.com that SWING!!
More information about the Python-list