Translations of this page?:

Apache Windows (apache rewrite)

Here are details about apache windows setting for a dokuwiki intranet. (apache 1.3 with EasyPhp1.7 or 1.8, not tested with Apache2)
It is only intended to show how to obtain 'nice addresses' with apapche - .htaccess - rewrite (not doku.php internal rewrite, which will be documented in Apache Windows 2 - internal rewrite -)
The goals are:
1/ no more IP server address: in an intranet, a first solution is to have an address like http://192.168.0.2/wiki/doku.php?id=…, wheras an address like http://mywiki/wiki/doku.php?id=… is more convenient;
2/ no more 'main' directory: instead of http://mywiki/wiki/doku.php, it would be better to have http://mywiki/doku.php?id=
3/ true address rewrite: no mode http://mywiki/doku.php?id=acategory:afile, but rather http://mywiki/acategory/afile


You can achieve the same result much more simply:

For (1), yes, modify the hosts file.

For (2), I don't see why an alias is necessary at all. Setting your vhost document root should be enough.
True but not clean: the alias is needed to be used in the directory-based rule RewriteBase /myalias, in the .htaccess file.

True, you could use RewriteBase /physicalpath, but that is not very clean in a per-directory file .htaccess…. – Daniel Chaffiol 01/06/2005

For (3), dokuwiki already provides settings to achieve this

$conf['basedir']     = '/';             //relative dir to serveroot - blank for autodetection
$conf['userewrite']  = 2;                //this makes nice URLs: 0: off 1: .htaccess 2: internal
$conf['useslash']    = 1;                //use slash instead of colon? only when rewrite is on
$conf['canonical']   = 1;                //Should all URLs use full canonical http://... style?


I have found it important to specify $conf['basedir'] and not let dokuwiki attempt autodetection.

The above works with Apache 2. I see no reason why it wouldn't work with Apache 1.3 as none of the settings is particularly controversial, though obviously that would be subject to testing :-).

Chris 2005-05-31

It 'almost'works (see page Apache Windows 2 - internal rewrite -), but this page is only for apache rewriting, not doku rewriting. Thanks for your comment which has helped me to clearly differenciate the two rewrinting mode. – Daniel Chaffiol 01/06/2005
You have still lost me. The standard .htaccess file provided with dokuwiki is sufficient to handle nice URLs with a userewrite setting of 1. You don't need a rewrite rule for each level. At least it does for me with Apache2. — Chris 2005-06-01
You do because (userewrite 1, default .htaccess), the addresses are 'http://mywiki/doku.php/cat1%3Bcat2%3Bcat3%3Bmyfile' (which is rewritten by the default .htaccess as doku.php?id=cat1%3Bcat2%3Bcat3%3Bmyfile and correctly decoded by the cleanID function of pageutils.php, instead of http://mywiki/cat1/cat2/cat3, which can not be rewritten as doku.php?id=cat1/cat2/cat3/myfile, hence my custom .htaccess with its 9 rules – Daniel Chaffiol 02/06/2005
Ok, my mistake, I didn't activated all the correct local.php options. The .htaccess is back to its (almost) default content. – Daniel Chaffiol 02/06/2005

Alias (DNS) and/or host file

The first point (replace a IP address by a name) can be achieve through:

  • a line in your host file (c:\windows\system32\drivers\etc\host): 127.0.0.1 mywiki (for local testing only)
  • a DNS alias (mywiki pointing on your apache server IP)

Alias (Apache) and Virtual Host

The second point (no more ‘main’ directory) can be achieve through a named virtual host, combined with an alias.
It supposes (in the httpd.conf) to:

  • have added the alias module (AddModule mod_alias.c)
  • add at then end of your httpd.conf (if your wiki files are under c:\mywiki):
#
# Use name-based virtual hosting.
#
NameVirtualHost 192.xxx.xxx.xxx:port <= physical address of your server

Alias "/wiki" "C:/mywiki"
<Directory "C:/mywiki">
	Options Indexes FollowSymLinks Includes
	AllowOverride All
	#Order allow,deny
	Allow from all
</Directory>
#alias
<VirtualHost mywiki> 
	ServerName mywiki.dnsdomain
	ServerAlias mywiki
	DocumentRoot C:/mywiki
	ErrorLog  logs/mywiki-error_log
	CustomLog logs/mywiki-access_log common
	#RewriteLogLevel 9
	#RewriteLog logs/mywiki-rewrite.log 
	RewriteEngine on
	RewriteRule ^/$		/doku.php  [NS,L]
</VirtualHost>

Plus, the option

$conf['basedir']     = '/';

must be set in the conf/local.php file.

Rewrite Rules (htaccess) and common.php

The third point (address rewriting) can be achieved through this following htaccess file:

## Enable this to restrict editing to logged in users only

#disable indexes
Options -Indexes

## make sure nobody gets the htaccess files
<Files ~ "^[\._]ht">
    Order allow,deny
    Deny from all
    Satisfy All
</Files>

# The following rules applies only if REQUEST_FILENAME is not an existing file or directory
## Comment these rules in if you want to have nice URLs
RewriteEngine on
RewriteBase /wiki
RewriteRule ^$                        doku.php  [NS,L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

That htaccess file silently rewrite an adress like http://mywiki/cat1/afile into /wiki/cat1/afile (through the RewriteBase rule), then into '/wiki/doku.php?id=cat1:afile'
It is the default .htaccess plus a “RewriteBase /wiki” rule.

But that supposes your wiki addresses (within the wiki pages) are created with '/'
That means the options

$conf['userewrite']  = 1;
$cconf['useslash'] = 1;
$cconf['canonical'] = 1;

have to be set in the local.php file
In the latest dokuwiki release (07.05.2005), add the following lines in inc/common.php:

function idfilter($id,$ue=true){
[...]
    $id = urlencode($id);
    $id = str_replace('%23','#',$id); //keep as diese    <== added
[...]

That way, the supposedly 'nice' address cat1/afile%23ananchor will actually by written with 'cat1/afile#ananchor'

Questions ?

What do you think of this dokuwiki address pattern (http://mywiki/category1/subcategory1/afile instead of http://mywiki/wiki/doku.php?id=category1:subcategory1:afile) ?
Daniel Chaffiol

I couldn't get the above solution to work with virtual hosts, since (as far as I can figure out) you need to have one IP address per virtual host. So even though my wiki at doku.mysite.com worked fine, that virtualhost also picked up flyspray.mysite.com (my bug tracker). So instead, I just added some more rewrite rules and got rid of the virtualhost:

<Directory "c:/path/to/DocumentRoot/">
  ....
  RewriteEngine on
  RewriteCond %{SERVER_NAME}            =doku.mysite.com
  RewriteCond %{REQUEST_URI}            !^/doku/
  RewriteRule (.*)                      doku/$1
</Directory>
...
Alias "/doku" "c:/path/to/dokuwiki"
<Directory "c:/path/to/dokuwiki">
  ...
</Directory>

The only problem I have with this, is that you can still access the wiki through http://doku.mysite.com/doku/doku.php, but the first link you click will properly redirect it to http://doku.mysite.com/. I'm not exactly sure how to fix this, but it's really not a big deal.

Fools guide to dokuwiki pretty URLs using Windows, Apache2 and .htaccess

Hopefully this simple step through will be helpful:

Apache2/conf/httpd.conf

  1. locate:
    #LoadModule rewrite_module modules/mod_rewrite.so
  2. Remove the #
  3. Also locate:
    #
    # This should be changed to whatever you set DocumentRoot to.
    #
    <Directory "C:/Program Files/Apache Group/Apache2/htdocs">
    ...
    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
        AllowOverride None
    
  4. Change None to All
  5. Restart the Apache server

Apache2/htdocs/dokuwiki/.htaccess

  1. Set the rewrite section to:
## Comment these rules in if you want to have nice URLs using
## $conf['rewrite'] = 1 - not needed for rewrite mode 2
#RewriteEngine on
RewriteEngine on
RewriteBase /dokuwiki  # Change this to the directory you have dokuwiki installed to
RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]
RewriteRule ^_export/([^/]+)/(.*)     doku.php?do=export_$1&id=$2  [QSA,L]
RewriteRule ^$                        doku.php  [NS,L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

Apache2/htdocs/dokuwiki/conf/local.php

  1. Set the following variables:
$conf['userewrite'] = '1';
$conf['useslash'] = 1;

Apache2/htdocs/dokuwiki/conf/dokuwiki.php

  1. Don't rely on autodetection for the basedir variable
$conf['basedir']     = '/dokuwiki';                //absolute dir from serveroot - blank for autodetection

If you've followed these instructions correctly then pretty urls should be working as follows:

Dave

 
wiki/discussion/apachewindows.txt · Last modified: 2006/12/15 20:56 by 74.14.228.158
 
Imprint Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
WikiForumIRCBugsTranslate