Better Dokuwiki SEO

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

So, I decided to do something about it.

First off, I noticed that lots of the errors were triggered by my security settings. Fixed those. And then I figured I’d fix the paths to be all the same.

Because isn’t that usually what happens. You try doing one thing, and it ends up being lots of them…

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

http://www.mattfiddles.com/doku.php?id=computers:filesystems&do=

Should be

http://www.mattfiddles.com/computers/filesystems

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.