HELP: BASE and LOCAL paths at the same time?

Discussion in 'HTML' started by ksamdev, Dec 14, 2008.

  1. ksamdev

    ksamdev Guest

    Hi,

    I have a site of next structure:

    js/...
    css/...
    img/...
    pages/1/index.html
    pages/1/img/...

    The idea is that page

    pages/1/index.html

    uses some js,css,img from top folders and at the same time has a
    number of images to be picked up from

    pages/1/img/

    folder. So, I tried to use BASE tag in head and specify path to my
    site:

    <base href='http://site'>

    so that JS, CSS, etc. would be picked up in HEAD with LINK tag using
    relative path. Very nice especially if I use another relative paths in
    my JS scripts say for images.

    But problem arises in index.html whenever I try to use any images from

    pages/1/img

    folder. There is a huge number of them and each time I specify
    ABSOLUTE path which is definitely not a best solution. I'd like to use
    at the same time relative to current page folder paths for these
    resources.

    Is there any way to use relative paths with BASE tag specified for JS,
    CSS, etc. and somehow link local files from page folder at the same
    time?
    ksamdev, Dec 14, 2008
    #1
    1. Advertising

  2. ksamdev wrote:
    > Hi,
    >
    > I have a site of next structure:
    >
    > js/...
    > css/...
    > img/...
    > pages/1/index.html
    > pages/1/img/...
    >
    > The idea is that page
    >
    > pages/1/index.html
    >
    > uses some js,css,img from top folders and at the same time has a
    > number of images to be picked up from
    >
    > pages/1/img/
    >
    > folder. So, I tried to use BASE tag in head and specify path to my
    > site:
    >
    > <base href='http://site'>
    >
    > so that JS, CSS, etc. would be picked up in HEAD with LINK tag using
    > relative path. Very nice especially if I use another relative paths in
    > my JS scripts say for images.
    >
    > But problem arises in index.html whenever I try to use any images from
    >
    > pages/1/img
    >
    > folder. There is a huge number of them and each time I specify
    > ABSOLUTE path which is definitely not a best solution. I'd like to use
    > at the same time relative to current page folder paths for these
    > resources.
    >
    > Is there any way to use relative paths with BASE tag specified for JS,
    > CSS, etc. and somehow link local files from page folder at the same
    > time?


    If I'm understanding your directory structure correctly, you don't need
    a base tag at all. Use relative URLs of the form

    /js/...
    /css/...
    /img/...
    /pages/1/img/ OR 1/img/...
    Harlan Messinger, Dec 14, 2008
    #2
    1. Advertising

  3. ksamdev

    ksamdev Guest

    On Dec 14, 12:21 pm, Harlan Messinger
    <> wrote:
    > ksamdev wrote:
    > > Hi,

    >
    > > I have a site of next structure:

    >
    > > js/...
    > > css/...
    > > img/...
    > > pages/1/index.html
    > > pages/1/img/...

    >
    > > The idea is that page

    >
    > >   pages/1/index.html

    >
    > > uses some js,css,img from top folders and at the same time has a
    > > number of images to be picked up from

    >
    > >   pages/1/img/

    >
    > > folder. So, I tried to use BASE tag in head and specify path to my
    > > site:

    >
    > >   <base href='http://site'>

    >
    > > so that JS, CSS, etc. would be picked up in HEAD with LINK tag using
    > > relative path. Very nice especially if I use another relative paths in
    > > my JS scripts say for images.

    >
    > > But problem arises in index.html whenever I try to use any images from

    >
    > >   pages/1/img

    >
    > > folder. There is a huge number of them and each time I specify
    > > ABSOLUTE path which is definitely not a best solution. I'd like to use
    > > at the same time relative to current page folder paths for these
    > > resources.

    >
    > > Is there any way to use relative paths with BASE tag specified for JS,
    > > CSS, etc. and somehow link local files from page folder at the same
    > > time?

    >
    > If I'm understanding your directory structure correctly, you don't need
    > a base tag at all. Use relative URLs of the form
    >
    >   /js/...
    >   /css/...
    >   /img/...
    >   /pages/1/img/ OR 1/img/...


    Thank you for reply.

    Your advice is perfectly correct.

    The only reason for use of BASE element is that local version of web
    site is used for development and access to it is done via base url:

    http://localhost/~myuser/

    Thus urls of type

    /js/...
    /css/...

    won't work because they will be related to

    http://localhost/

    instead of desired

    http://localhost/~myuser/

    Now resetting BASE tag in pages adopts my web site to whatever server
    I use.

    http://localhost/
    http://localhost/~user1/
    http://mysite/
    http://mysite/subsite/
    etc.

    At this point you may claim that appropriate APACHE setup with virtual
    hosting would be solution (at least for local development) but I want
    to stay with BASE solution if it is possible. Site would be self
    contained and can be put to any host even in subfolder as in case with
    example above:

    http://mysite/subsite/
    ksamdev, Dec 14, 2008
    #3
  4. On 2008-12-14, ksamdev wrote:
    ....
    > The only reason for use of BASE element is that local version of web
    > site is used for development and access to it is done via base url:
    >
    > http://localhost/~myuser/
    >
    > Thus urls of type
    >
    > /js/...
    > /css/...
    >
    > won't work because they will be related to
    >
    > http://localhost/
    >
    > instead of desired
    >
    > http://localhost/~myuser/


    Use relative paths instead: js/..., ../css/..., etc.


    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Dec 14, 2008
    #4
  5. ksamdev

    ksamdev Guest

    On Dec 14, 2:13 pm, "Chris F.A. Johnson" <> wrote:
    > On 2008-12-14, ksamdev wrote:
    >
    > ...
    >
    >
    >
    > > The only reason for use of BASE element is that local version of web
    > > site is used for development and access to it is done via base url:

    >
    > >  http://localhost/~myuser/

    >
    > > Thus urls of type

    >
    > >   /js/...
    > >   /css/...

    >
    > > won't work because they will be related to

    >
    > >  http://localhost/

    >
    > > instead of desired

    >
    > >  http://localhost/~myuser/

    >
    >    Use relative paths instead: js/..., ../css/..., etc.
    >
    > --
    >    Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
    >    ===================================================================
    >    Author:
    >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


    In that case my images within index.html won't be picked up from

    pages/1/img

    unless I specify full path including

    pages/1/img

    part like:

    <img src='pages/1/img/...' />

    Unfortunately in my real site implementation and folders hierarchy
    this path is a little longer than that and I have several pages of
    similar type:

    pages/1/index.html
    pages/2/index.html
    etc.

    each of which use their own set of images. # of images used per page
    is about 30 to 50. So, specifying long path is tedious. That's why I
    want to be able to use relative to given web-page path but at the same
    time all CSS, JS common to the whole site should rely on path that is
    related to:

    http://localhost/~user/

    or

    http://mysite.com/

    whichever I specify in BASE.
    ksamdev, Dec 14, 2008
    #5
  6. On 2008-12-14, ksamdev wrote:
    > On Dec 14, 2:13 pm, "Chris F.A. Johnson" <> wrote:
    >> On 2008-12-14, ksamdev wrote:
    >>
    >> ...
    >>
    >>
    >>
    >> > The only reason for use of BASE element is that local version of web
    >> > site is used for development and access to it is done via base url:

    >>
    >> > http://localhost/~myuser/

    >>
    >> > Thus urls of type

    >>
    >> > /js/...
    >> > /css/...

    >>
    >> > won't work because they will be related to

    >>
    >> > http://localhost/

    >>
    >> > instead of desired

    >>
    >> > http://localhost/~myuser/

    >>
    >> Use relative paths instead: js/..., ../css/..., etc.

    >
    > In that case my images within index.html won't be picked up from
    >
    > pages/1/img
    >
    > unless I specify full path including
    >
    > pages/1/img
    >
    > part like:
    >
    > <img src='pages/1/img/...' />
    >
    > Unfortunately in my real site implementation and folders hierarchy
    > this path is a little longer than that and I have several pages of
    > similar type:
    >
    > pages/1/index.html
    > pages/2/index.html
    > etc.
    >
    > each of which use their own set of images. # of images used per page
    > is about 30 to 50. So, specifying long path is tedious. That's why I
    > want to be able to use relative to given web-page path but at the same
    > time all CSS, JS common to the whole site should rely on path that is
    > related to:
    >
    > http://localhost/~user/
    >
    > or
    >
    > http://mysite.com/
    >
    > whichever I specify in BASE.


    If it doesn't work, it's because you are not specifying the correct
    path.

    If pages/1/index.html needs images in pages/1/img, the path is
    img/xxx.jpg; if the images are in pages/img, the path is
    ../../img/xxx.jpg, etc.

    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Dec 14, 2008
    #6
  7. ksamdev

    ksamdev Guest

    On Dec 14, 2:46 pm, "Chris F.A. Johnson" <> wrote:
    > On 2008-12-14, ksamdev wrote:
    > > On Dec 14, 2:13 pm, "Chris F.A. Johnson" <> wrote:
    > >> On 2008-12-14, ksamdev wrote:

    >
    > >> ...

    >
    > >> > The only reason for use of BASE element is that local version of web
    > >> > site is used for development and access to it is done via base url:

    >
    > >> >  http://localhost/~myuser/

    >
    > >> > Thus urls of type

    >
    > >> >   /js/...
    > >> >   /css/...

    >
    > >> > won't work because they will be related to

    >
    > >> >  http://localhost/

    >
    > >> > instead of desired

    >
    > >> >  http://localhost/~myuser/

    >
    > >>    Use relative paths instead: js/..., ../css/..., etc.

    >
    > > In that case my images within index.html won't be picked up from

    >
    > >   pages/1/img

    >
    > > unless I specify full path including

    >
    > >   pages/1/img

    >
    > > part like:

    >
    > >  <img src='pages/1/img/...' />

    >
    > > Unfortunately in my real site implementation and folders hierarchy
    > > this path is a little longer than that and I have several pages of
    > > similar type:

    >
    > >   pages/1/index.html
    > >   pages/2/index.html
    > >   etc.

    >
    > > each of which use their own set of images. # of images used per page
    > > is about 30 to 50. So, specifying long path is tedious. That's why I
    > > want to be able to use relative to given web-page path but at the same
    > > time all CSS, JS common to the whole site should rely on path that is
    > > related to:

    >
    > >  http://localhost/~user/

    >
    > > or

    >
    > >  http://mysite.com/

    >
    > > whichever I specify in BASE.

    >
    >   If it doesn't work, it's because you are not specifying the correct
    >   path.
    >
    >   If pages/1/index.html needs images in pages/1/img, the path is
    >   img/xxx.jpg; if the images are in pages/img, the path is
    >   ../../img/xxx.jpg, etc.
    >
    > --
    >    Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
    >    ===================================================================
    >    Author:
    >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


    Here is an example of index.html that is kept at:

    pages/1/index.html



    <html>

    <head>
    <base href='http://localhost/~user/' >
    <link href='./css/global.css' rel='stylesheet' type='text/css'>
    <script type='text/javascript' src='./js/lib.js'></script>
    </head>

    <body>
    <img src='img/1.png' />
    </body>

    </html>


    1.png should be taken from:

    http://localhost/~user/pages/1/img/

    folder and NOT

    http://localhost/~user/img/

    one of solutions is to replace img tag with:

    <imb src='./pages/1/img/1.png' />

    Question: can I somehow omit this ./pages/1 in img src attribute?
    ksamdev, Dec 14, 2008
    #7
  8. ksamdev

    ksamdev Guest

    On Dec 14, 2:46 pm, "Chris F.A. Johnson" <> wrote:
    > On 2008-12-14, ksamdev wrote:
    > > On Dec 14, 2:13 pm, "Chris F.A. Johnson" <> wrote:
    > >> On 2008-12-14, ksamdev wrote:

    >
    > >> ...

    >
    > >> > The only reason for use of BASE element is that local version of web
    > >> > site is used for development and access to it is done via base url:

    >
    > >> >  http://localhost/~myuser/

    >
    > >> > Thus urls of type

    >
    > >> >   /js/...
    > >> >   /css/...

    >
    > >> > won't work because they will be related to

    >
    > >> >  http://localhost/

    >
    > >> > instead of desired

    >
    > >> >  http://localhost/~myuser/

    >
    > >>    Use relative paths instead: js/..., ../css/..., etc.

    >
    > > In that case my images within index.html won't be picked up from

    >
    > >   pages/1/img

    >
    > > unless I specify full path including

    >
    > >   pages/1/img

    >
    > > part like:

    >
    > >  <img src='pages/1/img/...' />

    >
    > > Unfortunately in my real site implementation and folders hierarchy
    > > this path is a little longer than that and I have several pages of
    > > similar type:

    >
    > >   pages/1/index.html
    > >   pages/2/index.html
    > >   etc.

    >
    > > each of which use their own set of images. # of images used per page
    > > is about 30 to 50. So, specifying long path is tedious. That's why I
    > > want to be able to use relative to given web-page path but at the same
    > > time all CSS, JS common to the whole site should rely on path that is
    > > related to:

    >
    > >  http://localhost/~user/

    >
    > > or

    >
    > >  http://mysite.com/

    >
    > > whichever I specify in BASE.

    >
    >   If it doesn't work, it's because you are not specifying the correct
    >   path.
    >
    >   If pages/1/index.html needs images in pages/1/img, the path is
    >   img/xxx.jpg; if the images are in pages/img, the path is
    >   ../../img/xxx.jpg, etc.
    >
    > --
    >    Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
    >    ===================================================================
    >    Author:
    >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


    It won't work with path img/xxx.jpg because BASE tag of HEAD is
    changing relative path of ALL paths in document. In my case BASE is
    pointing to HTTP://LOCALHOST/~USER . So, browser attempts to download
    xxx.jpg from http://localhost/~user/img/ folder instead of web-page
    actual residence.
    ksamdev, Dec 14, 2008
    #8
  9. On 2008-12-14, ksamdev wrote:
    > On Dec 14, 2:46 pm, "Chris F.A. Johnson" <> wrote:
    >> On 2008-12-14, ksamdev wrote:
    >> > On Dec 14, 2:13 pm, "Chris F.A. Johnson" <> wrote:
    >> >> On 2008-12-14, ksamdev wrote:

    >>
    >> >> ...

    >>
    >> >> > The only reason for use of BASE element is that local version of web
    >> >> > site is used for development and access to it is done via base url:

    >>
    >> >> > http://localhost/~myuser/

    >>
    >> >> > Thus urls of type

    >>
    >> >> > /js/...
    >> >> > /css/...

    >>
    >> >> > won't work because they will be related to

    >>
    >> >> > http://localhost/

    >>
    >> >> > instead of desired

    >>
    >> >> > http://localhost/~myuser/

    >>
    >> >> Use relative paths instead: js/..., ../css/..., etc.

    >>
    >> > In that case my images within index.html won't be picked up from

    >>
    >> > pages/1/img

    >>
    >> > unless I specify full path including

    >>
    >> > pages/1/img

    >>
    >> > part like:

    >>
    >> > <img src='pages/1/img/...' />

    >>
    >> > Unfortunately in my real site implementation and folders hierarchy
    >> > this path is a little longer than that and I have several pages of
    >> > similar type:

    >>
    >> > pages/1/index.html
    >> > pages/2/index.html
    >> > etc.

    >>
    >> > each of which use their own set of images. # of images used per page
    >> > is about 30 to 50. So, specifying long path is tedious. That's why I
    >> > want to be able to use relative to given web-page path but at the same
    >> > time all CSS, JS common to the whole site should rely on path that is
    >> > related to:

    >>
    >> > http://localhost/~user/

    >>
    >> > or

    >>
    >> > http://mysite.com/

    >>
    >> > whichever I specify in BASE.

    >>
    >> If it doesn't work, it's because you are not specifying the correct
    >> path.
    >>
    >> If pages/1/index.html needs images in pages/1/img, the path is
    >> img/xxx.jpg; if the images are in pages/img, the path is
    >> ../../img/xxx.jpg, etc.

    >
    > Here is an example of index.html that is kept at:
    >
    > pages/1/index.html
    >
    >
    >
    ><html>
    >
    ><head>
    > <base href='http://localhost/~user/' >
    > <link href='./css/global.css' rel='stylesheet' type='text/css'>
    > <script type='text/javascript' src='./js/lib.js'></script>
    ></head>
    >
    ><body>
    > <img src='img/1.png' />
    ></body>
    >
    ></html>
    >
    >
    > 1.png should be taken from:
    >
    > http://localhost/~user/pages/1/img/


    Which is where it will be taken from if you use that relative URL.

    > folder and NOT
    >
    > http://localhost/~user/img/
    >
    > one of solutions is to replace img tag with:
    >
    > <imb src='./pages/1/img/1.png' />


    No, it's not. If index.html is in pages/1, you are looking for
    pages/1 in the same directory as index.html; it's not. It's in
    img/ or ./img

    >
    > Question: can I somehow omit this ./pages/1 in img src attribute?


    Of course, because it's wrong since pages/ is not in the directory
    you're in.

    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Dec 14, 2008
    #9
  10. ksamdev

    ksamdev Guest

    On Dec 14, 3:10 pm, "Chris F.A. Johnson" <> wrote:
    > On 2008-12-14, ksamdev wrote:
    > > On Dec 14, 2:46 pm, "Chris F.A. Johnson" <> wrote:
    > >> On 2008-12-14, ksamdev wrote:
    > >> > On Dec 14, 2:13 pm, "Chris F.A. Johnson" <> wrote:
    > >> >> On 2008-12-14, ksamdev wrote:

    >
    > >> >> ...

    >
    > >> >> > The only reason for use of BASE element is that local version of web
    > >> >> > site is used for development and access to it is done via base url:

    >
    > >> >> >  http://localhost/~myuser/

    >
    > >> >> > Thus urls of type

    >
    > >> >> >   /js/...
    > >> >> >   /css/...

    >
    > >> >> > won't work because they will be related to

    >
    > >> >> >  http://localhost/

    >
    > >> >> > instead of desired

    >
    > >> >> >  http://localhost/~myuser/

    >
    > >> >>    Use relative paths instead: js/..., ../css/..., etc.

    >
    > >> > In that case my images within index.html won't be picked up from

    >
    > >> >   pages/1/img

    >
    > >> > unless I specify full path including

    >
    > >> >   pages/1/img

    >
    > >> > part like:

    >
    > >> >  <img src='pages/1/img/...' />

    >
    > >> > Unfortunately in my real site implementation and folders hierarchy
    > >> > this path is a little longer than that and I have several pages of
    > >> > similar type:

    >
    > >> >   pages/1/index.html
    > >> >   pages/2/index.html
    > >> >   etc.

    >
    > >> > each of which use their own set of images. # of images used per page
    > >> > is about 30 to 50. So, specifying long path is tedious. That's why I
    > >> > want to be able to use relative to given web-page path but at the same
    > >> > time all CSS, JS common to the whole site should rely on path that is
    > >> > related to:

    >
    > >> >  http://localhost/~user/

    >
    > >> > or

    >
    > >> >  http://mysite.com/

    >
    > >> > whichever I specify in BASE.

    >
    > >>   If it doesn't work, it's because you are not specifying the correct
    > >>   path.

    >
    > >>   If pages/1/index.html needs images in pages/1/img, the path is
    > >>   img/xxx.jpg; if the images are in pages/img, the path is
    > >>   ../../img/xxx.jpg, etc.

    >
    > > Here is an example of index.html that is kept at:

    >
    > >   pages/1/index.html

    >
    > ><html>

    >
    > ><head>
    > >  <base href='http://localhost/~user/'>
    > >  <link href='./css/global.css' rel='stylesheet' type='text/css'>
    > >  <script type='text/javascript' src='./js/lib.js'></script>
    > ></head>

    >
    > ><body>
    > >  <img src='img/1.png' />
    > ></body>

    >
    > ></html>

    >
    > > 1.png should be taken from:

    >
    > >  http://localhost/~user/pages/1/img/

    >
    >    Which is where it will be taken from if you use that relative URL.
    >
    > > folder and NOT

    >
    > >  http://localhost/~user/img/

    >
    > > one of solutions is to replace img tag with:

    >
    > >  <imb src='./pages/1/img/1.png' />

    >
    >      No, it's not. If index.html is in pages/1, you are looking for
    >      pages/1 in the same directory as index.html; it's not. It's in
    >      img/ or ./img
    >
    >
    >
    > > Question: can I somehow omit this ./pages/1 in img src attribute?

    >
    >      Of course, because it's wrong since pages/ is not in the directory
    >      you're in.
    >
    > --
    >    Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
    >    ===================================================================
    >    Author:
    >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


    Chris, BASE tag in head changes scope of all links of current
    document !!!
    http://www.w3.org/TR/html401/struct/links.html#h-12.4

    That's why no matter where my web-page resides on server browser will
    treat all relative urls with respect to what is specified in BASE.
    ksamdev, Dec 14, 2008
    #10
  11. ksamdev

    ksamdev Guest

    Here is what I did after googling even though current solution is not
    the best one.

    Set BASE tag to site top folder and then specify all links with
    respect to that link.

    Anyway, please, continue this conversation especially in case you have
    any ideas on implementation because I would really like to have a web-
    site using both: links relative to BASE as well as ones relative to
    local web-page folder.
    ksamdev, Dec 15, 2008
    #11
  12. On 2008-12-14, ksamdev wrote:
    > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <> wrote:
    >> On 2008-12-14, ksamdev wrote:

    ....
    >> ><body>
    >> > <img src='img/1.png' />
    >> ></body>

    >>
    >> ></html>

    >>
    >> > 1.png should be taken from:

    >>
    >> > http://localhost/~user/pages/1/img/

    >>
    >> Which is where it will be taken from if you use that relative URL.
    >>
    >> > folder and NOT

    >>
    >> > http://localhost/~user/img/

    >>
    >> > one of solutions is to replace img tag with:

    >>
    >> > <imb src='./pages/1/img/1.png' />

    >>
    >> No, it's not. If index.html is in pages/1, you are looking for
    >> pages/1 in the same directory as index.html; it's not. It's in
    >> img/ or ./img
    >>
    >> > Question: can I somehow omit this ./pages/1 in img src attribute?

    >>
    >> Of course, because it's wrong since pages/ is not in the directory
    >> you're in.

    ....
    > Chris, BASE tag in head changes scope of all links of current
    > document !!!
    > http://www.w3.org/TR/html401/struct/links.html#h-12.4
    >
    > That's why no matter where my web-page resides on server browser will
    > treat all relative urls with respect to what is specified in BASE.


    Remove the BASE tag; you don't need it.

    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Dec 15, 2008
    #12
  13. ksamdev

    ksamdev Guest

    On Dec 14, 10:41 pm, "Chris F.A. Johnson" <>
    wrote:
    > On 2008-12-14, ksamdev wrote:
    > > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <> wrote:
    > >> On 2008-12-14, ksamdev wrote:

    > ...
    > >> ><body>
    > >> >  <img src='img/1.png' />
    > >> ></body>

    >
    > >> ></html>

    >
    > >> > 1.png should be taken from:

    >
    > >> >  http://localhost/~user/pages/1/img/

    >
    > >>    Which is where it will be taken from if you use that relative URL.

    >
    > >> > folder and NOT

    >
    > >> >  http://localhost/~user/img/

    >
    > >> > one of solutions is to replace img tag with:

    >
    > >> >  <imb src='./pages/1/img/1.png' />

    >
    > >>      No, it's not. If index.html is in pages/1, you are looking for
    > >>      pages/1 in the same directory as index.html; it's not. It's in
    > >>      img/ or ./img

    >
    > >> > Question: can I somehow omit this ./pages/1 in img src attribute?

    >
    > >>      Of course, because it's wrong since pages/ is not in the directory
    > >>      you're in.

    > ...
    > > Chris, BASE tag in head changes scope of all links of current
    > > document !!!
    > >http://www.w3.org/TR/html401/struct/links.html#h-12.4

    >
    > > That's why no matter where my web-page resides on server browser will
    > > treat all relative urls with respect to what is specified in BASE.

    >
    >    Remove the BASE tag; you don't need it.
    >
    > --
    >    Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
    >    ===================================================================
    >    Author:
    >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


    I do need it at least for local copy of site at:

    http://localhost/~user/
    ksamdev, Dec 15, 2008
    #13
  14. ksamdev

    dorayme Guest

    In article
    <>,
    ksamdev <> wrote:

    > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <>


    > >
    > >    Remove the BASE tag; you don't need it.
    > >

    >
    > I do need it at least for local copy of site at:
    >
    > http://localhost/~user/


    What platform are you on? Windows, Mac, Unix?

    --
    dorayme
    dorayme, Dec 15, 2008
    #14
  15. On 2008-12-15, ksamdev wrote:
    > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <>
    > wrote:
    >> On 2008-12-14, ksamdev wrote:
    >> > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <> wrote:
    >> >> On 2008-12-14, ksamdev wrote:

    >> ...
    >> >> ><body>
    >> >> > <img src='img/1.png' />
    >> >> ></body>

    >>
    >> >> ></html>

    >>
    >> >> > 1.png should be taken from:

    >>
    >> >> > http://localhost/~user/pages/1/img/

    >>
    >> >> Which is where it will be taken from if you use that relative URL.

    >>
    >> >> > folder and NOT

    >>
    >> >> > http://localhost/~user/img/

    >>
    >> >> > one of solutions is to replace img tag with:

    >>
    >> >> > <imb src='./pages/1/img/1.png' />

    >>
    >> >> No, it's not. If index.html is in pages/1, you are looking for
    >> >> pages/1 in the same directory as index.html; it's not. It's in
    >> >> img/ or ./img

    >>
    >> >> > Question: can I somehow omit this ./pages/1 in img src attribute?

    >>
    >> >> Of course, because it's wrong since pages/ is not in the directory
    >> >> you're in.

    >> ...
    >> > Chris, BASE tag in head changes scope of all links of current
    >> > document !!!
    >> >http://www.w3.org/TR/html401/struct/links.html#h-12.4

    >>
    >> > That's why no matter where my web-page resides on server browser will
    >> > treat all relative urls with respect to what is specified in BASE.

    >>
    >> Remove the BASE tag; you don't need it.

    >
    > I do need it at least for local copy of site at:
    >
    > http://localhost/~user/


    You do NOT need it if you use relative URLs. That is what is causing
    your problems.

    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Dec 15, 2008
    #15
  16. ksamdev

    ksamdev Guest

    On Dec 15, 12:41 am, dorayme <> wrote:
    > In article
    > <>,
    >
    >  ksamdev <> wrote:
    > > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <>

    >
    > > >    Remove the BASE tag; you don't need it.

    >
    > > I do need it at least for local copy of site at:

    >
    > >  http://localhost/~user/

    >
    > What platform are you on? Windows, Mac, Unix?
    >
    > --
    > dorayme


    OS X which is linux like.
    ksamdev, Dec 15, 2008
    #16
  17. ksamdev

    ksamdev Guest

    On Dec 15, 6:44 am, Harlan Messinger
    <> wrote:
    > ksamdev wrote:
    > > Your advice is perfectly correct.

    >
    > > The only reason for use of BASE element is that local version of web
    > > site is used for development and access to it is done via base url:

    >
    > >  http://localhost/~myuser/

    >
    > > Thus urls of type

    >
    > >   /js/...
    > >   /css/...

    >
    > > won't work because they will be related to

    >
    > >  http://localhost/

    >
    > > instead of desired

    >
    > >  http://localhost/~myuser/

    >
    > > Now resetting BASE tag in pages adopts my web site to whatever server
    > > I use.

    >
    > >  http://localhost/
    > >  http://localhost/~user1/
    > >  http://mysite/
    > >  http://mysite/subsite/
    > >   etc.

    >
    > > At this point you may claim that appropriate APACHE setup with virtual
    > > hosting would be solution (at least for local development) but I want
    > > to stay with BASE solution if it is possible. Site would be self
    > > contained and can be put to any host even in subfolder as in case with
    > > example above:

    >
    > >  http://mysite/subsite/

    >
    > Well, I don't think you can have it both ways. There isn't any way to
    > declare that URLs beginning with a slash are relative to one host while
    > URLs not beginning with a slash are relative to a path on a different host.
    >
    > I have the same situation, where I work with a site that is actually a
    > virtual directory within a larger site, and the pages pull in common
    > files from the larger site. In addition, we are required to use relative
    > URLs to reference all resources on the greater site, not just the ones
    > within our subsite. So for development, we download the common files in
    > order to have a local copy.


    Thanks.
    That is good but do you use relative paths with respect to HOST top
    folder?
    Say, if you have image:

    http://host/img/image.png

    and web-page

    http://host/pages/index.html

    then in index.html you put: src='./img/image.png' ?
    ksamdev, Dec 15, 2008
    #17
  18. ksamdev

    ksamdev Guest

    On Dec 15, 12:45 am, "Chris F.A. Johnson" <>
    wrote:
    > On 2008-12-15, ksamdev wrote:
    > > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <>
    > > wrote:
    > >> On 2008-12-14, ksamdev wrote:
    > >> > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <> wrote:
    > >> >> On 2008-12-14, ksamdev wrote:
    > >> ...
    > >> >> ><body>
    > >> >> >  <img src='img/1.png' />
    > >> >> ></body>

    >
    > >> >> ></html>

    >
    > >> >> > 1.png should be taken from:

    >
    > >> >> >  http://localhost/~user/pages/1/img/

    >
    > >> >>    Which is where it will be taken from if you use that relative URL.

    >
    > >> >> > folder and NOT

    >
    > >> >> >  http://localhost/~user/img/

    >
    > >> >> > one of solutions is to replace img tag with:

    >
    > >> >> >  <imb src='./pages/1/img/1.png' />

    >
    > >> >>      No, it's not. If index.html is in pages/1, you are looking for
    > >> >>      pages/1 in the same directory as index.html; it's not. It's in
    > >> >>      img/ or ./img

    >
    > >> >> > Question: can I somehow omit this ./pages/1 in img src attribute?

    >
    > >> >>      Of course, because it's wrong since pages/ is not in the directory
    > >> >>      you're in.
    > >> ...
    > >> > Chris, BASE tag in head changes scope of all links of current
    > >> > document !!!
    > >> >http://www.w3.org/TR/html401/struct/links.html#h-12.4

    >
    > >> > That's why no matter where my web-page resides on server browser will
    > >> > treat all relative urls with respect to what is specified in BASE.

    >
    > >>    Remove the BASE tag; you don't need it.

    >
    > > I do need it at least for local copy of site at:

    >
    > >  http://localhost/~user/

    >
    >   You do NOT need it if you use relative URLs. That is what is causing
    >   your problems.
    >
    > --
    >    Chris F.A. Johnson, webmaster         <http://Woodbine-Gerrard.com>
    >    ===================================================================
    >    Author:
    >    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


    Try yourself with:

    http://localhost/~chris/

    and you'll see that ~chris/ part will be ignored because it is a part
    of path and all relative uri's are treated with respect to host
    (unless BASE tag is set). Then you'll understand that base tag is
    needed.
    ksamdev, Dec 15, 2008
    #18
  19. ksamdev

    ksamdev Guest

    On Dec 15, 6:44 am, Harlan Messinger
    <> wrote:
    > ksamdev wrote:
    > > Your advice is perfectly correct.

    >
    > > The only reason for use of BASE element is that local version of web
    > > site is used for development and access to it is done via base url:

    >
    > >  http://localhost/~myuser/

    >
    > > Thus urls of type

    >
    > >   /js/...
    > >   /css/...

    >
    > > won't work because they will be related to

    >
    > >  http://localhost/

    >
    > > instead of desired

    >
    > >  http://localhost/~myuser/

    >
    > > Now resetting BASE tag in pages adopts my web site to whatever server
    > > I use.

    >
    > >  http://localhost/
    > >  http://localhost/~user1/
    > >  http://mysite/
    > >  http://mysite/subsite/
    > >   etc.

    >
    > > At this point you may claim that appropriate APACHE setup with virtual
    > > hosting would be solution (at least for local development) but I want
    > > to stay with BASE solution if it is possible. Site would be self
    > > contained and can be put to any host even in subfolder as in case with
    > > example above:

    >
    > >  http://mysite/subsite/

    >
    > Well, I don't think you can have it both ways. There isn't any way to
    > declare that URLs beginning with a slash are relative to one host while
    > URLs not beginning with a slash are relative to a path on a different host.
    >
    > I have the same situation, where I work with a site that is actually a
    > virtual directory within a larger site, and the pages pull in common
    > files from the larger site. In addition, we are required to use relative
    > URLs to reference all resources on the greater site, not just the ones
    > within our subsite. So for development, we download the common files in
    > order to have a local copy.


    BTW, this is the exact behavior I found and was really disappointed.
    Even HTML 4.01 specification defines that BASE overrides all relative
    paths (I am not talking about frames, embedded objects or Flash...
    those may have slight differences like CSS external files).

    My intuitive feeling was:

    ./path/img.png treat with respect to BASE element
    path/img.png '' '' '' local web-page
    path

    Unfortunately in both cases BASE is used (if it is set on page of
    course) otherwise script current folder is taken as bases.
    ksamdev, Dec 15, 2008
    #19
  20. On 2008-12-15, ksamdev wrote:
    > On Dec 15, 12:45 am, "Chris F.A. Johnson" <>
    > wrote:
    >> On 2008-12-15, ksamdev wrote:
    >> > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <>
    >> > wrote:
    >> >> On 2008-12-14, ksamdev wrote:
    >> >> > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <> wrote:
    >> >> >> On 2008-12-14, ksamdev wrote:
    >> >> ...
    >> >> >> ><body>
    >> >> >> > <img src='img/1.png' />
    >> >> >> ></body>

    >>
    >> >> >> ></html>

    >>
    >> >> >> > 1.png should be taken from:

    >>
    >> >> >> > http://localhost/~user/pages/1/img/

    >>
    >> >> >> Which is where it will be taken from if you use that relative URL.

    >>
    >> >> >> > folder and NOT

    >>
    >> >> >> > http://localhost/~user/img/

    >>
    >> >> >> > one of solutions is to replace img tag with:

    >>
    >> >> >> > <imb src='./pages/1/img/1.png' />

    >>
    >> >> >> No, it's not. If index.html is in pages/1, you are looking for
    >> >> >> pages/1 in the same directory as index.html; it's not. It's in
    >> >> >> img/ or ./img

    >>
    >> >> >> > Question: can I somehow omit this ./pages/1 in img src attribute?

    >>
    >> >> >> Of course, because it's wrong since pages/ is not in the directory
    >> >> >> you're in.
    >> >> ...
    >> >> > Chris, BASE tag in head changes scope of all links of current
    >> >> > document !!!
    >> >> >http://www.w3.org/TR/html401/struct/links.html#h-12.4

    >>
    >> >> > That's why no matter where my web-page resides on server browser will
    >> >> > treat all relative urls with respect to what is specified in BASE.

    >>
    >> >> Remove the BASE tag; you don't need it.

    >>
    >> > I do need it at least for local copy of site at:

    >>
    >> > http://localhost/~user/

    >>
    >> You do NOT need it if you use relative URLs. That is what is causing
    >> your problems.

    >
    > Try yourself with:
    >
    > http://localhost/~chris/
    >
    > and you'll see that ~chris/ part will be ignored because it is a part
    > of path and all relative uri's are treated with respect to host
    > (unless BASE tag is set). Then you'll understand that base tag is
    > needed.


    That is irrelevant. If you specify everything relative to the
    current file, you do not need a BASE tag.

    I have a few sites that I manage this way. On my local machine,
    they are:

    http://cj/cfaj.freeshell.org/
    http://cj/torquiz.freeshell.org/
    http://cj/woodbine-gerrard.com/

    On the Web, they are

    http://cfaj.freeshell.org/
    http://torquiz.freeshell.org/
    http://woodbine-gerrard.com/

    They have no BASE tags. There is no difference between the local
    files and the files on the Web.

    All references are relative to the current file. The sites could be
    moved anywhere and everything would still work.


    --
    Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
    ===================================================================
    Author:
    Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
    Chris F.A. Johnson, Dec 15, 2008
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noah
    Replies:
    5
    Views:
    752
  2. Replies:
    1
    Views:
    764
    Paul Boddie
    Mar 11, 2007
  3. Jonathan Wood
    Replies:
    1
    Views:
    2,170
    Jonathan Wood
    Nov 1, 2009
  4. Ohad Lutzky

    Paths, gentleman, paths

    Ohad Lutzky, Nov 6, 2006, in forum: Ruby
    Replies:
    2
    Views:
    176
    David Vallner
    Nov 7, 2006
  5. David Joseph Bonnici
    Replies:
    1
    Views:
    198
    Gunnar Hjalmarsson
    May 15, 2005
Loading...

Share This Page