[pmwiki-users] lots of problems when redirecting or rewriting URLs
DaveG
pmwiki at solidgone.com
Thu Jan 19 07:35:41 CST 2006
The whole thing is pretty clear to me now! Based on the idea of moving
.htaccess up to the root directory, I've now managed to get URL's:
From: http://dom.com/~nepherim/pmwiki/Home/HomePage/
To: http://dom.com/~nepherim/Main/HomePage
I'm having a problem (URL not found) with Editing, Uploading, and
History links (strangely Searching works fine).
I used this .htaccess inside "http://dom.com/~nepherim/":
Options +FollowSymLinks
RewriteEngine on
RewriteBase /~nepherim/
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^([^/a-z].*) index.php?n=$1 [QSA,L]
I put an index.php inside "http://dom.com/~nepherim/":
<?php chdir('pmwiki'); include 'pmwiki.php';
And I used these settings in config.php:
$BaseUrl = 'http://'.$_SERVER[HTTP_HOST].'/~nepherim';
$ScriptUrl = $BaseUrl;
$PubDirUrl = $BaseUrl.'/pmwiki/pub';
$ImgDirUrl = $ScriptUrl.'/pmwiki/img';
$UploadUrlFmt = $BaseUrl.'/pmwiki/uploads';
~ ~ Dave
DaveG wrote:
> I'm really getting confused, so I'm going to start from basics, going
> line by line through my current script and try to explain what little I
> understand to this point. Hopefully that will help educate those of us
> up in the back rows :)
>
> From there maybe the light will shine on how to remove that last little
> "pmwiki" (in fact I don't really care about that, I just want to
> understand this damn thing!).
>
> Any alterations or clarifications are welcome, and then I'll write all
> this up on a new wiki page for all to see.
>
> *Addendum:* As I was writing this, a *lot* became clear. The main thing
> I realized is that the intent of the .htaccess script is to change URLs
> FROM simple format INTO complex format (refer to definitions below).
> Pmwiki handles the conversion FROM complex format INTO simple format
> that is shown on the browser address bar. I had assumed the exact
> reverse, ie the script processes FROM complex to SIMPLE!
>
> --- *Questions*
> 1] What does $EnablePathInfo = 1; actually do? I think it:
> a) rewrites URL's on wiki pages to the simple format;
> b) rewrites the browser address bar URL to the simple format;
>
> Thus, the rewrites only need to convert from incoming simple format
> to the complex format so that PHP and thus Pmwiki can handle the request.
>
>
> --- *Definitions*
> In the text below, I'll use:
> - "complex URL": URL's in the format "/pmwiki.php?n=Main.HomePage".
>
> - "simple URL": URL's in the format "/Main/HomePage".
>
>
> --- *Background*
> PHP needs incoming URL's to be of the complex format in order to process
> them correctly. PHP (and thus pmwiki) cannot handle or process simple
> URLs, as there is no way to know which parts of the URL are parameters.
> Thus, the rules in .htaccess convert from simple format to complex format.
>
>
> --- *Analysis*
> 2] Here's the line by line script analysis, assuming the user enters a
> simple URL:
> http://dom.com/~nepherim/pmwiki/Main/HomePage
>
> and here's the complex URL we need to convert into so PHP can process:
> http://dom.com/~nepherim/pmwiki/pmwiki.php?n=Main.HomePage
>
> Pmwiki will handle the the conversion of the "complex URL" back into the
> simple format we will see in the browser address bar.
>
> #
> Options +FollowSymLinks
> Follow existing symbolic links. (Need more detail here.)
>
> #
> RewriteEngine on
> Turn on the rewrite engine.
>
> #
> RewriteBase /~nepherim/pmwiki/
> Strip out this part of the url, and leave us with whatever follows.
> Thus, from "http://dom.com/~nepherim/pmwiki/Main/HomePage" we now have
> "Main/HomePage".
>
> #
> RewriteCond %{QUERY_STRING} ^$
> Something to enable searching. What I'm not sure of is what condition
> needs to be satisfied to execute the following rewrite.
> (RewriteCond is basically an IF statement -- if the condition evaluates
> to true (AND RewriteCond's immediately following evaluate to true) then
> execute the next RewruteRule directive.)
>
> #
> RewriteRule ^/?$ ~nepherim/pmwiki/Main/HomePage/ [R=permanent,QSA,L]
> Alter URLs with a trailing "/" or with no trailing "/" to the HomePage.
> Thus, user entered URLs of "~nepherim/pmwiki" or "~nepherim/pmwiki/"
> translate to "~nepherim/pmwiki/Main/HomePage/".
>
> R=permenant: tell the browser that this redirect is permenant. Default
> is Temporary.
>
> QSA: Query String Append. If we have queries on the incomming URL, like
> "?action=edit" then append them to our new URL.
>
> L: Stop processing. In this case the next RewriteRule doesn't get
> processed, and we're done.
> *** Question: I must be misunderstanding this parameter. Why do we stop?
> If we stop here then we haven't converted to complex format.
>
> #
> RewriteRule ^([^/a-z].*) pmwiki.php?n=$1 [QSA,L]
> Here we're matching anything which is NOT a lowercase letter (a-z)
> followed by anything else. What this means in practice is that we're
> finding the pmwiki group and page name, since pmwiki groups always start
> with an uppercase character.
>
> (Differentiating between upper and lower case also prevents the
> processing of any internal pmwiki paths that are being used to create
> the page, like pub, upload, etc.)
>
> The first non-lowercase character we find in "Main/HomePage" is the
> first "M", so we take that and everything after: "Main/HomePage".
>
> This string is referenced by "$1". So, the Rewrite Rule replaces our
> "Main/HomePage" with "pmwiki.php?n=Main.HomePage".
>
> As we are done with the script, the Base part of the URL
> ("/~nepherim/pmwiki/") is now added back to what we created, so we end
> up with the complex URL PHP and pmwiki needs:
> /~nepherim/pmwiki/pmwiki.php?n=Main.HomePage
>
> ~ ~ Dave
>
>
>
> _______________________________________________
> pmwiki-users mailing list
> pmwiki-users at pmichaud.com
> http://host.pmichaud.com/mailman/listinfo/pmwiki-users
>
More information about the pmwiki-users
mailing list