Nice urls in MediaWiki
Contents
Problem
MediaWiki out of the box comes with urls like this:
http://www.fvue.nl/wiki/index.php?title=Nice_urls
But what would be very Web 2.0 is:
http://www.fvue.nl/wiki/Nice_urls
Problem is, the site has already been indexed by Google. And I don't want to bring those indexed links in jeopardy. These are the legacy urls I want to rewrite to new nice urls:
legacy url | new nice url |
---|---|
http://www.fvue.nl/wiki/index.php/Main_Page | /wiki/Main_Page |
http://www.fvue.nl/mediawiki-1.5.3/index.php/Main_Page | /wiki/Main_Page |
http://www.fvue.nl/wiki/index.php?title=Main_Page&redirect=no | /wiki/Main_Page |
Solution
These are the rewrite rules I've defined in .htaccess. If you define them in httpd.conf or conf.d, you need to add a leading slash to the RewriteRule pattern, i.e. change "RewriteRule ^index\.php$
" to "RewriteRule ^/index\.php$
". Also remember that you will need to restart your server before changes in these server config files take effect. [1]
#--- .htaccess ---------------------------------------------------------- RewriteEngine On # Rewrite legacy urls # 1. /wiki/index.php/Main_Page -> /wiki/Main_Page RewriteRule ^wiki/index.php/(.+)$ /wiki/$1 [L,R=301] # 2. /mediawiki-1.5.3/index.php/Main_Page -> /wiki/Main_Page RewriteRule ^mediawiki-[0-9\.]+/index.php/(.+)$ /wiki/$1 [L,R=301] # 3. /wiki/index.php?title=Main_Page&redirect=no -> /wiki/Main_Page RewriteCond %{QUERY_STRING} ^title=([^&]+) RewriteRule ^wiki/index.php /wiki/%1? [L,R=301] # Rewrite nice urls RewriteRule ^wiki/(.+)$ /w/index.php?title=$1 [L,QSA]
Journal
20061024
Ever since I started nice urls, Google has ignored them? No, here's an example of an indexed MediaWiki site with short urls: http://chickshare.com/wiki/Main_Page.
http://meta.wikimedia.org/wiki/Talk:Eliminating_index.php_from_the_url