Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > HELP: BASE and LOCAL paths at the same time?

Reply
Thread Tools

HELP: BASE and LOCAL paths at the same time?

 
 
ksamdev
Guest
Posts: n/a
 
      12-15-2008
On Dec 15, 8:54*am, "Chris F.A. Johnson" <(E-Mail Removed)> wrote:
> On 2008-12-15, ksamdev wrote:
> > On Dec 15, 12:45 am, "Chris F.A. Johnson" <(E-Mail Removed)>
> > wrote:
> >> On 2008-12-15, ksamdev wrote:
> >> > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <(E-Mail Removed)>
> >> > wrote:
> >> >> On 2008-12-14, ksamdev wrote:
> >> >> > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <(E-Mail Removed)> 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)


I see, you didn't get my initial point. I have a page that has to use
both paths:

relative to local folder (images specific to current page)
relative to top folder (external resources like: JS, CSS, etc.)

So, question was:

can I specify in my page somehow relation of path whether it has to
be understood by Browser wrt to local folder or top?

Answer: NO.

I can use only one type at a time. Decision was made in account of top
folder. That's why I use BASE link.

My website is heavily loaded with JS and all my libs, scripts should
be using at least relative path to top dir because it is used by
different pages on various levels. This way BASE makes sure everything
works fine.

Downside of current approach - my all img links should be defined
using relative path wrt host that makes it very long. Say:

<img src='pages/articles/1/img/section1/1.png' />

I thought there is some way to get rid of this redundancy especially
if you have say 50 images . JS may be used for this reason but it's
another complication. My original idea is to keep site as simple as it
can be.
 
Reply With Quote
 
 
 
 
Chris F.A. Johnson
Guest
Posts: n/a
 
      12-15-2008
On 2008-12-15, ksamdev wrote:
> On Dec 15, 8:54 am, "Chris F.A. Johnson" <(E-Mail Removed)> wrote:
>> On 2008-12-15, ksamdev wrote:
>> > On Dec 15, 12:45 am, "Chris F.A. Johnson" <(E-Mail Removed)>
>> > wrote:
>> >> On 2008-12-15, ksamdev wrote:
>> >> > On Dec 14, 10:41 pm, "Chris F.A. Johnson" <(E-Mail Removed)>
>> >> > wrote:
>> >> >> On 2008-12-14, ksamdev wrote:
>> >> >> > On Dec 14, 3:10 pm, "Chris F.A. Johnson" <(E-Mail Removed)> 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.

>
> I see, you didn't get my initial point. I have a page that has to use
> both paths:
>
> relative to local folder (images specific to current page)
> relative to top folder (external resources like: JS, CSS, etc.)


If it is external, it is not relative to the top folder (or
anything else on your site). If it is not external, it can be
specified relative to the current folder.

> So, question was:
>
> can I specify in my page somehow relation of path whether it has to
> be understood by Browser wrt to local folder or top?
>
> Answer: NO.


YES!


--
Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
 
Reply With Quote
 
 
 
 
Harlan Messinger
Guest
Posts: n/a
 
      12-15-2008
ksamdev wrote:
> On Dec 15, 6:44 am, Harlan Messinger
> <(E-Mail Removed)> 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' ?


No, "/img/image.png".
 
Reply With Quote
 
ksamdev
Guest
Posts: n/a
 
      12-15-2008
On Dec 15, 9:31*am, Harlan Messinger
<(E-Mail Removed)> wrote:
> ksamdev wrote:
> > On Dec 15, 6:44 am, Harlan Messinger
> > <(E-Mail Removed)> 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' ?

>
> No, "/img/image.png".


This is the same in given case.
 
Reply With Quote
 
Bergamot
Guest
Posts: n/a
 
      12-15-2008

Harlan Messinger wrote:
> ksamdev wrote:
>>
>> 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' ?

>
> No, "/img/image.png".


Or "../img/image.png"

--
Berg
 
Reply With Quote
 
Harlan Messinger
Guest
Posts: n/a
 
      12-15-2008
ksamdev wrote:
> On Dec 15, 6:44 am, Harlan Messinger
> <(E-Mail Removed)> 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.


There isn't any basis for your intuition the BASE tag only works for
URLs that start with a dot. The BASE tag means "for all purposes,
interpret relative URLs on this page relative to *this* URL". And how
could it be otherwise? What if your part of the site was itself on
multiple levels?

http://example.com/mysite/page1.html
http://example.com/mysite/apple/page1.html
http://example.com/mysite/banana/page1.html

How, under the scheme you envisioned, would you create a link in either
of the lower-level pages leading to the higher-level page? If you used
BASE to refer to the production server, then on your development server
that link (whether you coded it as "/mysite/page1.html" or as
"../page1.html") would take you to the live copy of the page, not to the
development copy. How could you specify that you mean the local copy?
 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      12-15-2008
ksamdev wrote:

> and web-page
>
> http://host/pages/index.html
>
> then in index.html you put: src='./img/image.png' ?


If you sue relative path from http://host/pages/index.html to
http://host/img/image.png it would be:

<img src="../img/image.png">
^^
Note the 2 dots!

That would work as long as the relative paths between to document and
the image remains the same.

http://www.example.com/very/very/dee...ges/index.html
to
http://www.example.com/very/very/dee.../img/image.png



--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
ksamdev
Guest
Posts: n/a
 
      12-15-2008
On Dec 15, 9:48*am, Harlan Messinger
<(E-Mail Removed)> wrote:
> ksamdev wrote:
> > On Dec 15, 6:44 am, Harlan Messinger
> > <(E-Mail Removed)> 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.

>
> There isn't any basis for your intuition the BASE tag only works for
> URLs that start with a dot. The BASE tag means "for all purposes,
> interpret relative URLs on this page relative to *this* URL". And how
> could it be otherwise? What if your part of the site was itself on
> multiple levels?
>
> http://example.com/mysite/page1.html...ana/page1.html
>
> How, under the scheme you envisioned, would you create a link in either
> of the lower-level pages leading to the higher-level page? If you used
> BASE to refer to the production server, then on your development server
> that link (whether you coded it as "/mysite/page1.html" or as
> "../page1.html") would take you to the live copy of the page, not to the
> development copy. How could you specify that you mean the local copy?


Agree on that.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paths, gentleman, paths Ohad Lutzky Ruby 2 11-07-2006 02:15 AM
absolute paths when using "View in Browser" on local port Amil Hanish ASP .Net 1 07-16-2006 11:58 PM
Local LAN Access - Works for WinXP, No Go For Linux - Same Server,Same Laptop Marc Schwartz Cisco 0 06-18-2005 02:28 PM
Virtual Directory, Paths, Local and Deployed Problem nick ASP .Net 8 10-01-2004 04:15 PM
Convert between Windows style paths and POSIX style paths Noah Python 5 07-11-2003 09:25 PM



Advertisments