Sunday, 4 March 2018

Re: linking to root of website, not root of drive

[Email copy of news posting to comp.sys.acorn.misc]

Posted in Netsurf users, as it follows up a question and in c.s.a.misc
because it's not NetSurf specific. Please reply in Usenet.

In article <6c94decc56.ricp@user.minijem.plus.com>, Richard Porter
<ricp@minijem.plus.com> wrote:
> On 19 Feb 2018 Jim Nagel wrote:

> > Is there a way around this? Is there some setting I would need to
> > make in Netsurf to define what I mean by "/" as root? (Presumably
> > there is such a setting in my ISP's software, for I am not being
> > taken to the root of their drive!)

> I have the same problem. I'm running WebJames with its root directory
> as the directory containing my web sites. That means that "/" on the
> local site takes me back to the top level and not the root of the site
> I want.

I was just having a similar problem to Jim's original and have a solution
wrt setting the BASE tag depending on server, local or distant. The same
technique could of course be applied to just the style sheet location, or
whatever. It uses PHP but don't let that put you off.

Let's imagine the URL of the distant server you upload to is
http://domain.tld/
and your local WebJames copy is here
http://localhost/domain/

First of all, save this fragment of php as file 'pathname/php' and/or
'pathname.php' in both locations:
<?php
$pathname = dirname(__FILE__);
print("Pathname = $pathname");
?>
Then run it from your browser:
http://domain.tld/pathname.php
and
http://localhost/domain/pathname.php

You will see something like
Pathname = /ISPname/users/8/4/s112113/htdocs
and
Pathname = /Sunfish::Web_Sites.$/domain

(Or, at least, that's what I see: my WebJames serves sites stored on a
NAS accessed with Sunfish)

Once you know a string to differentiate the location of where your file
is running, this would then work in the HEAD of your index.php file, or
whatever, in place of the BASE tag:

<?php
$pathname = dirname(__FILE__);
if ( substr($pathname,1,7) == "ISPname" ) {
$base = "http://domain.tld/";
} else {
$base ="http://localhost/domain/";
}
print("<base href=\"$base\">\n");
?>

If your WebJames server has an external URL, use that in place of
localhost, obviously.

HTH

(Replies in c.s.a.misc please; this is OT for NetSurf-Users.)

--

Tim Hill

timil.com : tjrh.eu : butterwick.eu : blue-bike.uk : youngtheatre.co.uk

No comments:

Post a Comment