Difference between revisions of "Friendly URL's"

From Organic Design wiki
Line 1: Line 1:
[[Catgegory:MediaWiki]]
+
[[Category:MediaWiki]]
 +
 
 +
= Mod-rewrite rules =
 +
We use [http://httpd.apache.org/docs/mod/mod_rewrite.html mod-rewrite] to change the illegally formatted "friendly" request into a legitimate request directed at the ''index.php'' script like usual. Mod-rewrite is used to specify a condition pattern, and a transformation rule to apply to the URL if it matches the condition pattern. Our mod-rewrite directives are as follows:
 +
<pre>
 +
    RewriteEngine On
 +
    RewriteCond %{REQUEST_URI} !^/w.*/
 +
    RewriteRule ^/(.*) /wiki/index.php/$1 [L]
 +
</pre>
 +
The [[w:mod rewrite]]re-write condition says not to touch any URL's which start with a lowercase ''W'' and start and finish with a forward slash, this protects all old-style article requests, and requests to internal MediaWiki files like scripts or images. It also allows other directories of web documents outside the wiki such as http://www.organicdesign.co.nz/www/media
 +
 
 +
The re-write rule then assumes everything after the leading slash to be an article name and reformats the URL accordingly. Also <tt>$wgArticlePath = "/$1"</tt> is set in ''LocalSettings.php'' to make the friendly form the default way of rendering links. Links involving a query-string will use the usual format.
 +
 
 +
= Bug fixes =
 +
*It was transforming to <tt>...index.php?title=$1</tt>, but this cause the ampersand bug, see [[17 February 2007]] news item.
 +
*Its been improved now so that URL's are only left alone if requesting a folder (following slash) of name starting with lowercase ''W''. This fixes a bug where articles starting with ''W'' had to be specified with capital first letter. [[User:Nad|Nad]] 14:25, 14 Feb 2006 (NZDT)
 +
 
 +
= See also =
 +
*[http://www.mediawiki.org/wiki/Manual:Short_URL MediaWiki's manual entry]
 +
*[http://meta.wikimedia.org/wiki/Make_non-ugly_URLs WikiMedia article on freindly URL's]

Revision as of 03:38, 17 February 2007


Mod-rewrite rules

We use mod-rewrite to change the illegally formatted "friendly" request into a legitimate request directed at the index.php script like usual. Mod-rewrite is used to specify a condition pattern, and a transformation rule to apply to the URL if it matches the condition pattern. Our mod-rewrite directives are as follows:

    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/w.*/
    RewriteRule ^/(.*) /wiki/index.php/$1 [L]

The w:mod rewritere-write condition says not to touch any URL's which start with a lowercase W and start and finish with a forward slash, this protects all old-style article requests, and requests to internal MediaWiki files like scripts or images. It also allows other directories of web documents outside the wiki such as http://www.organicdesign.co.nz/www/media

The re-write rule then assumes everything after the leading slash to be an article name and reformats the URL accordingly. Also $wgArticlePath = "/$1" is set in LocalSettings.php to make the friendly form the default way of rendering links. Links involving a query-string will use the usual format.

Bug fixes

  • It was transforming to ...index.php?title=$1, but this cause the ampersand bug, see 17 February 2007 news item.
  • Its been improved now so that URL's are only left alone if requesting a folder (following slash) of name starting with lowercase W. This fixes a bug where articles starting with W had to be specified with capital first letter. Nad 14:25, 14 Feb 2006 (NZDT)

See also