[pmwiki-users] Real Clean URLs

Patrick R. Michaud pmichaud at pobox.com
Mon Sep 19 13:43:29 CDT 2005


On Mon, Sep 19, 2005 at 08:00:09PM +0200, Steffen Bauch wrote:
> Patrick R. Michaud wrote:
> >>Can you explain what you mean with "partial url"?
> >
> >An example would be a url that leads to a group's home page,
> >such as the one associated with the group names on pmwiki.org.
> >For example, the group name "PITS" at the top of a PITS issue
> >links to "http://www.pmwiki.org/wiki/PITS".  
> >
> So, for normal URLs a change in $FmtP for PageUrl would suffix,
> changing  '$ScriptUrl/$Group/$Name' to  '$ScriptUrl/$Group/$Name.html'

It would do some, but it's not sufficient to catch all, because
some links are actually formed directly from $ScriptUrl.  For example,
skin templates often contain things like

    <a href='$ScriptUrl/$Group/RecentChanges'>Recent Changes</a>

which would obviously need to have a ".html" placed on the end of
it somewhere but doesn't use $PageUrl.

However, perhaps a solution that gets us most of the way there is

    $FmtP['!\\$ScriptUrl/[^?#\'"\\s<>./]+[./][^?#\'"\\s<>./]+!'] = '$0.html';

which adds '.html' to anything that looks like a reference to a
page (i.e., $ScriptUrl followed by a group and page name, excluding
any query string or url fragment).

Looks pretty close -- see http://www.pmwiki.org/Test/WithHtml .

Of course, the links won't work right because pmwiki.org doesn't
have the mod_rewrite rule in place to strip off the ".html".  But 
another way to remove the .html without using mod_rewrite might be 
to just do it in the local/config.php file directly (at the very 
very top, just after the <?php line):

    $pagename = preg_replace('/\\.html/', '', $pagename);

which basically says to get rid of any trailing ".html" from 
the pagename.  Since page names have to begin with an uppercase letter
and cannot contain dots, this shouldn't form any collisions with
existing pages.   Note that this has to go in config.php and not
a per-group or per-page customization file, because PmWiki has
to establish a correct pagename before it can load those files.  :-)

Just to see if this can work, I've gone ahead and set pmwiki.org 
to strip ".html" from any incoming page names, so that the page
links on Test.WithHtml will work.  Looks pretty good from the
testing I've done thus far.

Anyone have a problem with me placing the "automatically strip .html
from incoming page names" into the core?  Or should we just leave this
as something that administrators are required to do in the local/config.php
file?  

(More properly, if not done in the core then it would really need to
be done in the farmconfig.php file for farms.  We can't easily do this
via some sort of $EnableXYZ option, because cookbook recipes and
other customizations really depend on having a proper $pagename prior
to being called.)

> And for partial URLs? Could this be done with some clever mod_rewrite
> command?

Partial URLs for groups would seem to work the same as they do now -- 
they look like "directories" which become redirects to the correct 
page within the group.

Pm




More information about the pmwiki-users mailing list