[pmwiki-users] Protocol (https/http) included in $ScriptUrl

Bart pmwiki-users at mediamatrix.nl
Thu Sep 7 17:23:31 CDT 2006


On Thu, Sep 07, 2006 at 03:40:42PM -0500, Patrick R. Michaud wrote:
| On Thu, Sep 07, 2006 at 10:10:46PM +0200, Nils Knappmeier wrote:
| > this is not urgent, since I solved it by setting $ScriptUrl manually, 
| > but anyway.
| > 
| > It would be nice, if the protocol part of the URL (https or http) would 
| > be used as protocol part, of $ScriptUrl.
| > At the moment, $ScriptUrl is composed as
| >     $ScriptUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
| > 
| > Is it possible, in future releases, to change this to
| > 
| > if ($_SERVER['HTTPS'] == 'on') {
| >     $ScriptUrl = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
| > } else {
| >     $ScriptUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
| > }
| > 
| > or something similar?
| 
| There's a number of issues related to this, also having to do with
| relative versus absolute links.  They're described in:
| 
|     http://www.pmwiki.org/wiki/PITS/00526
|     http://www.pmwiki.org/wiki/PITS/00527
|     http://www.pmwiki.org/wiki/PITS/00595
|     http://www.pmwiki.org/wiki/PITS/00619
| 
| and we should also probably consider
| 
|     http://www.pmwiki.org/wiki/PITS/00764
| 
| It might be nice to really resolve this one, since it would close
| at least five PITS entries.  :-)
| 
| Pm
| 


Good evening from The Netherlands Europe 

I ran into this problem myself a while ago when setting up a Pmwiki that
uses both http:// and https:// the first for public access the second for
secure password transfer during editing. 

First I used the approach as Nils put up and even wrote a script to patch
pmwiki.php to patch after a new update. When I implemented clean urls's with
rewrite rule I had to take a closer look at the whole URL structure. As not
being a programmer but far more a tracker I found myself deciphering what
actually is happening in the whole process of building and rewriting the URL
and where the 

lines 73 and  74 of pmwiki.php 
$ScriptUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
$PubDirUrl = preg_replace('#/[^/]*$#','/pub',$ScriptUrl,1);
kick in 

Important for the rewrite is setting the $ScriptUrl in config.php to the right
value. Than I it dawned on me that this overrules line 73 of pmwiki.php
which I didn't realize before... From config.php I just could play with it
:-)

In a flash I realized that this was the way to also solve the http: https:
switch :-)

$ScriptUrl = $_SERVER['SCRIPT_NAME'];

I know this was also mentioned in http://www.pmwiki.org/wiki/PITS/00526 but
just pasting the two lines in config.php didn't work when I tried that a few
weeks ago and I didn't understand what was happening at that time. 


What i try to illustrate with this story is cause of the absolute URL in
pmwiki.php the new user busy with exploring Pmwiki's treasure box is easily
set on the wrong trail getting things working in http and https, using to
complex tricks with absolute URL's

A decant configured server should just be able working with relative URL's
Apache is :-)

I realize that this doesn't work for some setups (PITS/00526)
But I suspect this is more a exception and likely a misconfiguration in
server directives. Missing or double slash when using relative URL's or
what so ever. But normally relative URL's just should work a lot of
applications use and rely on them. 

Please correct me on my story when I wrong. I actually take a strong
stand here, but in fact I am not sure if my point is waterproof, but I like
to find out if what i am thinking is a real valid point of view. 

So what I propose is dropping the absolute URL in favor for the relative URL
This solves the whole https issue at hand in just one step! Relative URL's
just should work on a proper configured server

Of course I don't want to exclude anyone, users who run into a relative URL
issue that can't be solved easy can switch to absolute by adding the next
line to there config.php or farm.php

$ScriptUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];

It's a wise idea to put up a PITS or Cookbook page addressing this, including
the http:// https:// switch trick Nils already mentioned.

For my clean URL rewrite I ended up with the next lines in config.php which
is really clean and tide and of course the usual rewrite stuff in .htaccess

$ScriptUrl = dirname($_SERVER['SCRIPT_NAME']);
$PubDirUrl = $ScriptUrl.'/pub';

Here dirname strips index.php from the relative URL PubDir is than just
appending /pub to the scripturl. The original idea to do it this way isn't
mine but comes from some other code snippet somewhere in the cookbook. :-)

I apologize that this is a bit lengthy post, but I hope that I accomplished
to give a clear picture of what I experienced and at this moment think is
the best way for achieving a long term solution for the current situation.

Best regards, Bart





More information about the pmwiki-users mailing list