Nice urls in MediaWiki

From FVue
Jump to: navigation, search


MediaWiki out of the box comes with urls like this:

But what would be very Web 2.0 is:

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 /wiki/Main_Page /wiki/Main_Page /wiki/Main_Page


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]



Ever since I started nice urls, Google has ignored them? No, here's an example of an indexed MediaWiki site with short urls:


blog comments powered by Disqus