#110 wiki page links should be relative

Linking
closed
Reini Urban
1
2012-10-11
2002-03-13
Andrew Dorrell
No

A number of people here use wiki via an ssh tunnel.
This means that the URL they enter in their browser
looks something like:

http://localhost:9080/phpwiki/index.php

The ssh tunnel is responsible for accepting data on
localhost port 9080 and redirecting it to port 80 on a
server behind our firewall. This is all standard practice.

Problem is that phpwiki puts all its wiki links in as
absolute links using the fully qualified name of the
server it is running on. Bummer - none of these links
will work over the tunnel as the hostname part needs to
be localhost:redirected-port. Obviously I cannot enter
this as the server name in the wiki configuration. The
only solution is to make wiki generate html with
relative links

Discussion

  • Cuthbert Cat
    Cuthbert Cat
    2002-04-09

    Logged In: YES
    user_id=11619

    In phpwiki/lib/config.php you'll find the following code:

    define('BASE_URL', SERVER_URL . (USE_PATH_INFO ?
    VIRTUAL_PATH . '/' : SCRIPT_NAME));

    This is the base included at the top of each dynamically
    generated html page - all local links are relative, they
    just use the base variable as well) - so change it to suit
    your situation. Try putting a temporary "phpinfo();" at
    this point and reload to see what globals have been
    defined - you might find an ORIGINAL_SSL_PORT variable or
    some such. If all else fails, just put:

    define('BASE_URL', "http://localhost:9080" .
    (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));

    ...or even...

    define
    ('BASE_URL', "http://localhost:9080/phpwiki/index.php");

    However, the more you hardwire it in, the less flexible
    it'll be for the future. If you can find suitable globals
    to use as conditionals or as the BASE_URL then you're more
    likely to be able to access the wiki in other situations
    (e.g. when you're already behind the firewall, or on the
    hosting machine itself).
    Hope this helps,

    Cuthbert Cat

     
  • Andrew Dorrell
    Andrew Dorrell
    2002-04-09

    Logged In: YES
    user_id=445617

    Thanks - you're right...

    I tried to put define('SERVER_URL', ""); immediately prior
    but that didn't work. However replacing

    define('BASE_URL',
    SERVER_URL . (USE_PATH_INFO ? VIRTUAL_PATH . '/' :
    SCRIPT_NAME));

    with:

    define('BASE_URL',
    "" . (USE_PATH_INFO ? VIRTUAL_PATH . '/' : SCRIPT_NAME));

    works almost everywhere :-). I have tested most links using
    a server running on the same machine as the client. It
    fails in one case: after performing an edit you hit save for
    the first time??? going back (browser button) and hitting
    save for a second time gets the relative address (that is,
    it works as expected the second time around) - why? I get
    this behaviour for both konqeror and mozilla so I assume its
    not a browser issue.

    One further issue of course is that you must specify the
    full path to the main wiki page in your initial URL (ie it
    must include index.php) otherwise none of the page links
    will work!

    In fact, looking a little further in the source code reveals
    it is the result of an unresolved issue in calculating the
    'VIRTUAL_PATH' (see config.php lines 211-265)... this is
    where I got to initially with this problem. I really don't
    understand what tha author is trying to achieve with the
    virtual path stuff so I am in no position to suggest how to
    fix it... and the current code is a tad messy here.

    This fix will serve my purpose for the moment however - thanks!