It's better when it's simple

User Tools

Site Tools


Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community

Follow us on Facebook, Twitter and other social networks.

Our Privacy Policy


URL Rewriting

By default, DokuWiki does no URL rewriting, resulting in URLs like this:

These URLs are considered ugly and are not indexed well by some search engines.

The solution is to enable URL rewriting, which is disabled by default.

Instructions in plain English


  1. Go to Admin
  2. Open Configuration Settings
  3. Change Nice URLs option to .htaccess (use find, it's far down)
  4. Underneath it, check the option to “Use slash as namespace separator in URLs”
  5. Save
  6. Next, using an ftp or file manager, you need access to your /wiki/ folder that you created when creating your wiki.
  7. Inside, you'll find a file called .htaccess and .htaccess.dist. (if you don't see it, make sure you have hidden files visible. It may be an option you have while logging on depending on your hosting provider, or, simply create a file called .htaccess and upload it)
  8. inside the .htaccess file, paste the following (alternatively uncomment section in .htaccess.dist then rename to .htaccess):
RewriteEngine on
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  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

This will give you a format like If you have a different format for your address, like, then place this line right after RewriteEngine on

RewriteBase /dokuwiki

where /dokuwiki should be changed to the actual name of the folder you are using.

Further Details for the Technically Savvy

DokuWiki supports two methods for URL rewriting, enabled through the userewrite option. One relies on the rewriting capabilities of the webserver; the other one handles rewritten URLs inside DokuWiki. The table below summarizes these options.

Value Info Example URL
0 No URL rewriting is used. This is the default.
1 Rewriting is handled by the webserver.
2 Rewriting is done by DokuWiki.

URL-Rewriting is disabled by default because it requires some additional configuration besides setting the appropriate config option - these configs are discussed below.

URL-Rewriting can be enabled at ?do=admin&page=config#_advanced or in the local conf/local.php file line that reads $conf['userewrite'] = N;. N is the number 0, 1, or 2. The default is zero without this line present. Follow the configuration instructions below for whichever option is chosen.

Option 1: web server

:!: Remember to set following in the Configuration Manager /start?do=admin&page=config

  • Use nice URLs: .htaccess
  • Use slash as namespace separator in URLs [x]

Otherwise rewrite rules will not be useful.


Rewriting URLs in Apache is done through the mod_rewrite module of Apache 1 or Apache 2.

DokuWiki comes with an .htaccess.dist file which contains the needed rewrite rules for mode 1.

Here is an example

RewriteEngine on
RewriteBase /dokuwiki
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  [L]
RewriteCond %{REQUEST_FILENAME}       !-f
RewriteCond %{REQUEST_FILENAME}       !-d
RewriteRule (.*)                      doku.php?id=$1  [QSA,L]
RewriteRule ^index.php$               doku.php

On the line RewriteBase /dokuwiki, you may need to replace the /dokuwiki with whatever directory you use in your URL to get to the wiki. If your wiki appears at the top level of the domain (e.g. points to the start page of the wiki then use the following line: RewriteBase /.

You may also need to rename the file from .htaccess.dist to .htaccess.

Apachectl status broken

Dokuwiki rewrite rule affect apachectl status command and make it return dokuwiki 404 page instead of the server-status page. You can fix that by either putting this in dokuwiki rewrite rules

RewriteCond %{REQUEST_URI} !^/server-status$

or creating an empty server-status file in dokuwiki root folder where doku.php is located. See forum post Apachectl status is broken with dokuwiki

404 not found error

You may need to do this.

IIS (or Microsoft Azure Web App)

Enable url rewriting and insert appropriate set of rules:

<rule name="rule 1C" stopProcessing="true">
	<match url="^_media/(.*)" />
	<action type="Rewrite" url="/lib/exe/fetch.php?media={R:1}" appendQueryString="true" />
<rule name="rule 2C" stopProcessing="true">
	<match url="^_detail/(.*)" />
	<action type="Rewrite" url="/lib/exe/detail.php?media={R:1}" appendQueryString="true" />
<rule name="rule 3C" stopProcessing="true">
	<match url="^_export/([^/]+)/(.*)" />
	<action type="Rewrite" url="/doku.php?do=export_{R:1}&amp;id={R:2}" appendQueryString="true" />
<rule name="rule 4C" stopProcessing="true">
	<match url="^$" />
	<action type="Rewrite" url="/doku.php" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<rule name="rule 5C" stopProcessing="true">
	<match url="(.*)" />
	<action type="Rewrite" url="/doku.php?id={R:1}" appendQueryString="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<rule name="rule 6C">
	<match url="^index.php$" />
	<action type="Rewrite" url="/doku.php" />

If you are using Azure Web App, just put these lines under the <system.webServer> tags in web.config file (situated in wwwroot of your App).

IIS 7.0 or greater

IIS 7.0 and above can be extended with a the URL Rewrite module 2.0 available from Microsoft for both x86 and x64

Save the Apache rules above to a .htaccess file removing the “RewriteBase /dokuwiki” line. This will not be required as we will be adding the rules directly to the root of the wiki.

In IIS Manager select your Wiki folder, and under IIS select “URL Rewrite” (if you had Manager open before installing, a refresh will be required)

In the actions pane on the right hand side, choose “Import Rules”

For your configuration file, select the .htaccess file and Import, this should give you 6 converted rules.

Finally hit Apply in the Actions panel on the right hand side.

Configure your Wiki to use .htaccess rules for rewrite and you should now be seeing your URLs rewritten.


See nginx documentation. In the following example, our server root is /var/www, and we extract dokuwiki to /var/www/wiki.

server {
    listen 80;
    #maximum file upload size is 4MB - change accordingly if needed
    client_max_body_size 4M;
    client_body_buffer_size 128k;
    root /var/www/wiki;
    index doku.php;
    location / { try_files $uri $uri/ @dokuwiki; }
    location @dokuwiki {
        rewrite ^/_media/(.*) /lib/exe/fetch.php?media=$1 last;
        rewrite ^/_detail/(.*) /lib/exe/detail.php?media=$1 last;
        rewrite ^/_export/([^/]+)/(.*) /doku.php?do=export_$1&id=$2 last;
        rewrite ^/(.*) /doku.php?id=$1&$args last;
    location ~ \.php$ {
        if (!-f $request_filename) { return 404; }
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param REDIRECT_STATUS 200;


If using https the HTTPS server variable has to be set to allow proper linking in dokuwiki. This can be done in the server section with:

fastcgi_param HTTPS on;

The last keyword of rewrite rules before location setup make sure that rewrite only happens once. You should replace all /dokuwiki/ appeared above to you wiki directory relative to web server root directory.

If you are copy-pasting these configs, make sure you are adding locations to secure some of the directories as described on Security page.

httpd (OpenBSD)

See also httpd documentation. By default the server root is /var/www and dokuwiki is in /var/www/dokuwiki

server "default" {
  listen on egress port 443
  root "/dokuwiki"
  directory index doku.php
  # Set according to upload_max_filesize and post_max_size in php.ini  
  connection max request body 20971520  
  location "*.php"     { fastcgi socket "/run/php-fpm.sock" }
  # Block access to non-public dirs
  location "/data/*"   { block }
  location "/conf/*"   { block }
  location "/bin/*"    { block }
  location "/inc/*"    { block }
  location "/vendor/*" { block }
  # URL rewrite rules  
  location match "/media/(.*)" {
    request rewrite "/lib/exe/fetch.php?media=%1"
  location match "/detail/(.*)" {
    request rewrite "/lib/exe/detail.php?media=%1"
  location match "/export/([^/]+)/(.*)" {
    request rewrite "/doku.php?do=export_%1&id=%2"
  location match "/(lib/.*)" {
    request rewrite "/%1"
  location match "/([^lib])" {
    request rewrite "/doku.php?id=$DOCUMENT_URI&$QUERY_STRING"

Option 2: DokuWiki

In your conf/local.php file, add or modify the line so it reads:

$conf['userewrite'] = 2;

This option won't need any webserver setup. However it relies on the PATH_INFO feature of the CGI standard as implemented by Apache. IIS is known not to work with this setting. However, new IIS versions seem to work with this.

Clean PHP session ID

Despite using “clean” URLs you may encounter a “DokuWiki” parameter in the URL looking like this:

PHP session ID:

This parameter is the PHP session ID and gets added by PHP automatically. It's completely unrelated to rewriting. To avoid it you can force PHP to always use cookies for sessions by setting the session.use_only_cookies option for PHP.

This is usually done in the php.ini config file:


You can also try:


Also see

rewrite.txt · Last modified: 2020-10-05 16:56 by