Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84344

[OT] absolute vs. relative URI

From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject [OT] absolute vs. relative URI
Date 2015-01-23 14:47 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <m9tmt8$hbn$1@reader1.panix.com> (permalink)

Show all headers | View raw


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'
   else
     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
current server:

  <a src='/Whatever'>Whatever</a>

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!!

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

[OT] absolute vs. relative URI Grant Edwards <invalid@invalid.invalid> - 2015-01-23 14:47 +0000
  Re: [OT] absolute vs. relative URI Marko Rauhamaa <marko@pacujo.net> - 2015-01-23 17:18 +0200
    Re: [OT] absolute vs. relative URI Grant Edwards <invalid@invalid.invalid> - 2015-01-23 15:40 +0000
      Re: [OT] absolute vs. relative URI Chris Warrick <kwpolska@gmail.com> - 2015-01-23 17:00 +0100
        Re: [OT] absolute vs. relative URI Grant Edwards <invalid@invalid.invalid> - 2015-01-23 17:10 +0000
      Re: [OT] absolute vs. relative URI Chris Angelico <rosuav@gmail.com> - 2015-01-24 04:48 +1100
        Re: [OT] absolute vs. relative URI Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-23 11:02 -0800
          Re: [OT] absolute vs. relative URI Chris Angelico <rosuav@gmail.com> - 2015-01-24 06:46 +1100
          Re: [OT] absolute vs. relative URI Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-01-23 20:22 +0000
  Re: [OT] absolute vs. relative URI Chris Angelico <rosuav@gmail.com> - 2015-01-24 04:55 +1100
  Re: [OT] absolute vs. relative URI Tony the Tiger <tony@tiger.invalid> - 2015-01-23 18:21 +0000

csiph-web