I was getting some errors with my Dokuwiki site. Some search engine was hitting some links and causing errors. Grrr….

So, I decided to do something about it. I noticed that lots of the errors were triggered by my security settings. Fixed those.

But while doing so, I noticed that I didn’t like how my urls looked. And I decided to fix them up.

Trying to Look Good

I have “pretty links” set up on dokuwiki. I like them. The only problem is that sometimes they don’t work like I’d want them to. Like:


Should be


Simple. I want it to be more SEO friendly. But it wasn’t doing it. And google was complaining about it. So I added some htaccess rules to fix it. Much better.

First, I got rid of the do=search term:

# show all search paths the same
RewriteCond %{QUERY_STRING} ^do=search&id=(.*) [OR]
RewriteCond %{QUERY_STRING} ^id=(.*)&do=search
RewriteRule ^(.*)$ /search/%1? [R=301,L]
# Then put this above the dokuwiki part:
RewriteRule ^search/(.*)              doku.php?directsearch=yes&do=search&id=$1  [QSA,L]
# don't put these in, just here to help you place it in the right place
RewriteRule ^_media/(.*)              lib/exe/fetch.php?media=$1  [QSA,L]
RewriteRule ^_detail/(.*)             lib/exe/detail.php?media=$1  [QSA,L]

You’ll note the use of “directsearch=yes” as a parameter. Without this, you’ll get infinite loops.

On the other hand, if you want to keep do=search, but make it more uniform:

# show all search paths the same 
RewriteCond %{QUERY_STRING} do=search&id=(.*)
RewriteRule ^(.*)$ /%1?do=search [R=301,L]

Now we get rid of doku.php regardless of if the user (or bot) tries to use it or not.

# get rid of doku.php 
RewriteCond %{THE_REQUEST} /?doku\.php\?id=([^&]*).* [NC]
RewriteRule ^(.*)$ /%1? [R=301,L]

Oh, and get rid of ‘:’ if we want to use ‘/’s.

# redirect /doku.php?id=computers:filesystems&do= 
# to /computers/filesystems 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^(.*):(.*)$ $1/$2 [R=301,L]

You can use the above on your dokuwiki site. Just make sure they work like they are suppose to. You’ll have to do some modifications if you have your dokuwiki in a subfolder.

And no more ?do=search$id=searchterm or id=searchterm&do=search nonsense. The doku.php will never show and cause duplicate pages, and we have nice ‘/’ instead of ‘:’.

Nice and Simple.