Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

CleanUrls-Comments

This page contains all comments from the CleanUrls page.

Renaming to shorten URLs

I'm new to PmWiki, but what I did was this:

  1. I created a file called i.php in the same directory as pmwiki.php. The contents of I were <?php include_once('pmwiki.php');
  2. Then, I renamed the folder called that I previously had titled "PmWiki" to "w"
  3. I put this into my config.php file:
      ## Eliminate "pmwiki.php" from URLs.
      $EnablePathInfo = 0;
      $ScriptUrl = "http://put your domain name here/w/i.php";
      ## more configuration settings...

Finally, I pointed my server to i.php and it worked with a short URL!

Ok,I tried this exact process (with a Windows server) and this is what I got "Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\wikifolder\myinformation.php:1) in E:\xampp\htdocs\wikifolder\pmwiki.php on line 1075," can someone advise?

thanks! -Chris August 24, 2008

Trying to remove pmwiki.php with .htaccess

I'm trying to remove the pmwiki.php using .htaccess but have so far failed, hopefully you guys can help me out.

In my config file I have:

## Use "Clean URLs".
$EnablePathInfo = 1;
$ScriptUrl = "http://www.mydomain.com/necrowiki";
## more configuration settings...

Then in my .htaccess file, which is located in the same dir as pmwiki.php:

# Use mod_rewrite to enable "Clean URLs" for a PmWiki installation.
RewriteEngine On
# Define the rewrite base.
RewriteBase /necrowiki
# Send requests without parameters to pmwiki.php.
RewriteRule ^$           pmwiki.php  [L]
# Send requests for index.php to pmwiki.php.
RewriteRule ^index\.php$ pmwiki.php  [L]
# Send requests to pmwiki.php, appending the query string part.
RewriteRule ^([^/a-z].*) pmwiki.php?n=$1  [QSA,L]

Anybody know why it isn't working?

Remove www from URL

Also add this and you will remove the www from all URLs for your site. It is completely compatible with CleanUrls.

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

Lowercase Group Names

Does anyone know how to use rewriting capabilities to allow lower-case group names to be entered and successfully redirected to the title-cased group names? e.g. http://mywiki.com/group redirects to http://mywiki.com/Group. —JoeW? 2006-08-25

Yes, the rewrite rule should be

RewriteRule ^([^/].*) pmwiki.php?n=$1  [QSA,L]

instead of

RewriteRule ^([^/a-z].*) pmwiki.php?n=$1  [QSA,L]

which just means the page name can't start with a forward slash, but anything else is fine. — Sam Wilson 2007-02-02.

Even cleaner URLs

I also use the following (plus some modifications of php code) to get even cleaner URLs:

# If of form Group/Name/action, 
# send requests to pmwiki.php with proper arguments appended ($3 is query string)
RewriteRule ^([A-Z0-9][^/.]*[/.][^/]*)[/]([a-z]+)(.*) pmwiki.php?n=$1&action=$2&args=$3 [QSA,L]
# Send requests to pmwiki.php, appending the query string part.
RewriteRule ^([^/a-z].*) pmwiki.php?n=$1  [QSA,L]
2006-03-23 AriEpstein

Simplify further for group main pages
For having the main page of each group display as {wikiroot}/group instead of {wikiroot}/group/group, add the following to your local/config.php file:

##  Even cleaner URLs: group main pages display as /$group and not /$group/$group
$EnableFixedUrlRedirect=0;
$FmtPV['$PageUrl'] = '($name==$group) ? "$ScriptUrl/$group" : "$ScriptUrl/$group/$name"';
2007-08-09 EemeliAro

Sam Brenner 2-7-2006
Apache 2.0.54 came default with the rewrite module turned off and .htaccess turned off.

In your http.conf file uncomment:

#LoadModule rewrite_module modules/mod_rewrite.so

or you will get an "Internal Server Error" message.

Then you will have to enable the use of .htaccess

Someone recommended using the following script directories as an alternative to hardcoding the servername.

$BaseUrl = 'http://'.$_SERVER['HTTP_HOST'];
$ScriptUrl = $BaseUrl.'/pmwiki';
$PubDirUrl = $BaseUrl.'/pmwiki/pub';
$UploadDir = '/uploads';
$UploadUrlFmt=$BaseUrl.'/pmwiki/uploads';

Using the $_SERVER[HTTP_HOST] variable solved a Netscape localhost name issue.

For recent PmWiki releases you should be able to replace the five lines above with
$ScriptUrl = 'http://'.$_SERVER['HTTP_HOST'].'/pmwiki';
$PubDirUrl = 'http://'.$_SERVER['HTTP_HOST'].'/pmwiki/pub';
$UploadDir = '/uploads';
although that $UploadDir setting looks incorrect. Try leaving that line out, or replacing it with
$UploadDir =
  realpath($UploadDir = dirname(__FILE__).'/../uploads');

Thank you for all the work on this. The URL Rewriting (mod_rewrite + .htaccess) is so clear that I was able to immediately see what I broke when I moved my pmwiki directory down a level.

--Pico

Clean URLs in WikiFarms

Am I correct in concluding that each Wiki Field would need its own distinct .htaccess file to ensure that each field queries itself? When you say to "place the .htaccess file in the directory that will correspond the shortest URL that will reach the wiki" does that mean, in the context of WikiFarms, the directories that correspond to the shortest URLs that will distinctly reach one (and only one) Farm? See here for more.

--Pico

Yes, each field wiki needs its own distinct .htaccess because each field wiki has its own distinct URL. Does this rewrite of the note about farms make that point clearer?

Another thing to check is the Apache error log. For example you may see the error message Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden

I tried approach #3, first (simple suggestion, Eliminating "pmwiki.php" From URLs), but the shortened URLs did not display the desired pages.

It seems that index.php was not processed. Maybe this recipe requires certain webserver settings to work that are not in place on my server? I noticed that I also had to remove the trailing slash, or the path names would be displayed as http://my.url.com//Group/Page. (As you can see, I have already switched off the /n= part of the URL. I hope this doesn't complicate things.)

Henning March 24, 2006, at 09:22 AM

Henning,
Your parenthetical comment is the key. Approach #3 doesn't include setting $EnablePathInfo to 1. It must be set to 0. In other words, you can use $EnablePathInfo OR hide index.php, but not both (as far as I know).

This brings up an important point because you can (sometimes) use index.php + $EnablePathInfo to have clean URLs, too. In other words, you can do this

Before: http://www.example.com/~someuser/pmwiki/pmwiki.php?n=Main.HomePage
 After: http://www.example.com/~someuser/index.php/Main/HomePage

Here's an index.php file for the corresponding directory (/home/someuser/public_html/):

<?php
chdir('pmwiki');
include_once('pmwiki.php');

Here's the matching local/config.php file, which simply turns on $EnablePathInfo:

<?php if (!defined('PmWiki')) exit();
## Use "Clean URLs".
$EnablePathInfo = 1;
## more configuration settings...

--Hagan

The samedir mod-rewrite method breaks links to http://site.com/path/to/pmwiki.php?action=blah, apparently causing POST data to be dropped.

A direct link to [blah]/pmwiki.php?action=login and [blah]/pmwiki.php?action=mailform2 (see Mailform2) causes both of these actions to fail.

This quote from Mailform2 may be helpful:

If you applied the CleanUrls recipe and have a redirect rule installed, make sure that the ?action=mailform2 URL above goes to the "unclean" URL (the one that contains pmwiki.php). Otherwise, form input data will be dropped by Apache, and all you'll get is seemingly empty input fields.

This is happening with the samedir mod-rewrite method regardless of whether the link (in the case of ?action=login) or the form (in the case of Mailform2) is directed to the "unclean" URL. -- Neurophyre, 7 Aug 2006

'RewriteRule ^index\.php$ ~someuser/pmwiki/pmwiki.php [L]' doesn't work on Aplus.net

I'm hosting a wiki on aplus.net, and it seems that '^index\.php$' doesn't work as expected.

'RewriteRule ^index.php$ ~someuser/pmwiki/pmwiki.php [L]' works as expected, but it also rewrites 'index_php', 'indexQphp'...

Shigeru Kobayashi December 28, 2006, at 09:29 AM

ISAPI module link broken

The link to iismods.com generates an error (Bad Request (Invalid Hostname)). A little googling turned up Ionic's ISAPI Rewrite Filter which is free but not open-source. I've no idea whether the .ini syntax modeled on the CleanURLS page is compatible or not. Alas, I'm in a shared IIS hosting environment and can't use it. -thomas taylor, 03/05/2007

Minimum required "Options" for mod_rewrite

the web server I use is very restrictive by default. The apache option FollowSymLinks was disabled. This has to be enabled in order for mod_rewrite to work. To fix this, add the following to the top of the .htaccess file:

Options +FollowSymLinks

99% of the people out there won't need this, but for the other 1%, here you go. Without this you will get a "403 Forbidden" error message --Vrillusions June 04, 2007, at 10:46 AM

Even cleaner

Some people might also be interested in GetRidOfMain. I had a hard time finding it. Jeff 7/19/07

It keeps renaming lowercase urls to group names - Paulo

I'm using pmwiki on the root of my site and have this line on my .htaccess:

RewriteRule ^([A-Z0-9\xa0-\xff].*)$ web/pmwiki.php?n=$1 [QSA,L]

I thinks this Regular Expression doesn't work at all because it ignores casing. The best Regex would be: ^([A-Z][a-z\xa0-\xff].*)$

I had problems to access sub-directories in the root of my website (like: domain.com/forum). This regex matches only the strings that starts with uppercased letters and then, sends to pmwiki.php.

Showing images have been used in skin when using clean Urls

When you use clean urls with it will not show pictures have been set relative to pmwiki.php. To solve this problem you should add a line before the line sends parameters to pmwiki so those lines will be like the following:

RewriteRule ^([A-Z0-9\xa0-\xff].*\.(jpg|gif))$ $1 [L]
RewriteRule ^([A-Z0-9\xa0-\xff].*)$ pmwiki.php?n=$1 [QSA,L]

This works except when you want to upload a picture so if you want to upload a picture the parameters won't be sent and you can't do it so a better regex for eliminating this problem is appreciated.Soroush

mod_rewrite with Apache 1.3 on Windows

When using Apache 1.3 on Windows, the RewriteRule for CleanUrls does not work properly, since Apache 1.3 always lowercases the URI before providing it to mod_rewrite. This does not work (the original recipe with .htaccess and pmwiki.php in the Same Directory):

RewriteBase  /pmwiki
RewriteRule  ^([A-Z0-9\xa0-\xff].*)$  pmwiki.php?n=$1  [QSA,L]

Change it to

RewriteBase  /pmwiki
RewriteCond  %{REQUEST_URI}  ^/pmwiki/[A-Z0-9\xa0-\xff]
RewriteRule  ^(.*)$  pmwiki.php?n=$1  [QSA,L]

Important: The path at RewriteBase and RewriteCond must be equal (here: /pmwiki).
Apache 2.x on Windows is not affected (AFAIK).
20080314 RRipley

Edit - History - Print - Recent Changes - Search
Page last modified on August 24, 2008, at 10:12 AM