[pmwiki-users] Clean URLS cookbook question

Patrick R. Michaud pmichaud at pobox.com
Mon Feb 6 08:27:47 CST 2006


On Sun, Feb 05, 2006 at 03:16:58PM -0700, H. Fox wrote:
> > So, $PubDirUrl is set using the value of $ScriptUrl that is coming
> > from mod_rewrite (works), but $UploadUrlFmt is being set using the
> > value of $ScriptUrl from config.php (doesn't work).
> 
> Oh, I see.  and I think I have a solution...
> 
> It looks to me like $PubDirUrl and UploadUrlFmt are nearly always the
> same, except for one ends in "pub" and the other ends in "uploads". 
> Is that the case?  

Yes, it is, and yes, you're correct that using $PubDirUrl
as a base seems to make a lot more sense than $ScriptUrl.

> If so, you could replace
>   SDV($UploadUrlFmt,preg_replace('#/[^/]*$#',"/$UploadDir",$ScriptUrl,1));
> with something like
>   $UploadDirBase = basename($UploadDir);
>   SDV($UploadUrlFmt,preg_replace('#/[^/]*$#',"/$UploadDirBase",$PubDirUrl,1));
> and nail it that way.

That looks pretty reasonable, although I'm not sure about always using
basename() here.  I think I want to use basename only if $UploadDir
starts with a slash.  OTOH, if someone is changing the location of
$UploadDir anyway then they really ought to be explicitly setting
$UploadUrlFmt at the same time.

> This brings me to the subject of accurately guessing $ScriptUrl, which
> I'll save for its own thread.

I definitely look forward to it.  :-)

> Ideally it will rarely be necessary to set either one of them.  :-)

Absolutely.

Pm




More information about the pmwiki-users mailing list