MediaWiki and clean URLs

apps

#1

You can have clean URLs with the one-click install of Mediawiki. Here’s how.

Install the wiki into www.yourdomain.com/w and NOT into www.yourdomain.com/wiki, using the Dreamhost one-click install menu.

Modify the following in LocalSettings.php after you have set it up:

$wgArticlePath = "/wiki/$1"; In the ROOT directory of www.yourdomain.com, place the following .htaccess file:

[code]RewriteEngine on

uncomment this rule if you want Apache to redirect from www.mysite.com/ to www.mysite.com/wiki/Main_Page

RewriteRule ^/$ /wiki/Main_Page [R]

do the rewrite

RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]
[/code]Note that I haven’t tested the redirect RewriteRule, as I use an index.php in my root directory that sends a Location header, so I can more easily take the site down for maintenance.


#2

A couple of questions:

1.) What is the technical difference between using “w” as the name of the directory and “wiki”? In theory shouldn’t it not matter what the name of the directory is?

2.) I have multiple installations of Mediawiki installed, so if I place this .htaccess file in my root directory will it affect every Mediawiki installation I have?


#3

What is the technical difference between using “w” as the name of the directory and “wiki”?

One benefit of installing Mediawiki into a directory different from the one it is (or appears to be, via mod_rewrite) served out of is that you can disallow search engines from indexing the actual installation directory. This will prevent edit pages from turning up in search results. I believe this is one of the reasons Wikipedia takes this approach.

The name of the installation directory doesn’t matter, as long as it’s different from the “virtual” directory you want the wiki pages served from. One of my sites uses a method similar to the one in the Mediawiki docs, with Mediawiki installed into /mw, while the content URLs begin with /wiki.

Using this approach, you can then add the following to /robots.txt:

User-Agent: * Disallow: /mw

If you want useful replies, ask smart questions.


#4

“The name of the installation directory doesn’t matter, as long as it’s different from the “virtual” directory you want the wiki pages served from. One of my sites uses a method similar to the one in the Mediawiki docs, with Mediawiki installed into /mw, while the content URLs begin with /wiki.”

Oh, I was unaware that the installation directory was not where the wiki pages are served from. I didn’t see anything in the wiki configuration about which directory I wanted the wiki pages served from so I assume the default IS “/wiki” or how do I/can I changed that directory?

Apropos the root of this thread, in particular the bit which reads: “Modify the following in LocalSettings.php after you have set it up:
$wgArticlePath = “/wiki/$1”;”

I find two "$wgArticlePath ="s. Which one do I modify or do I modify one and delete the other one?

I’ve been having a very difficult time trying to get clean urls working for my wikis so please forgive my newbie ignorance.


#5

Here’s a fun trick I like to use:

ln -s wiki_media/index.php ./wikiPut in my .htaccess file:

[code]AddHandler dh-php /cgi-system/php5.cgi

<Files “wiki”>
SetHandler dh-php
[/code]Then point your Wiki configs to use www.domain.com/wiki as the URL and tell it to use “pretty” URLs. It’ll start using: www.domain.com/wiki/Start_Page, etc.

Feel free to play with it however you please. It’s a nice way to pretty up the URLs w/out relying on RewriteRule which can slow down the server.


[MediaWiki] Short URLs using AddHandler/SetHandler
#6

Is there any way to do that with mediawiki in the root of the site address?


#7

I’m sure there is, but I don’t have MediaWiki to give you the exact syntax. The only difference would be you wouldn’t have a media_wiki directory. You’ll have to point ‘wiki’ to index.php and set media wiki to use /wiki/ as it’s index page.


#8

what if i wanted to move my wiki from a different host? im using godaddy… and want to move to DH. is that possible and still have nice clean urls?


#9

If you are running a WordPress blog and a MediaWiki wiki on the same site, the mod_rewrite rules for these two applications can interfere with each other (you will get 404 errors when trying to access /wiki/* URLs).

I found that putting the MediaWiki rewrite rules first works. For example, if mydomain.com/ maps to your WordPress installation in ~/mydomain.com/ and mydomain.com/wiki/ maps to your wiki install in ~/mydomain.com/w/ (not /wiki), then your ~/mydomain.com/.htaccess will look like this:

BEGIN MediaWiki

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/?(.*)$ /w/index.php?title=$1 [L,QSA]

END MediaWiki

BEGIN WordPress

RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]