Difference between revisions of "Friendly URL's"
(→Bug fixes: Rewrite rules updated on 29 June 2011 to fix a long-standing bug preventing thumbnails from working for images with ampersands in their titles) |
(formatting) |
||
Line 1: | Line 1: | ||
− | |||
− | |||
− | |||
− | |||
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: | 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> | + | {{code|<pre> |
RewriteEngine On | RewriteEngine On | ||
RewriteCond %{REQUEST_URI} ^/$ | RewriteCond %{REQUEST_URI} ^/$ | ||
RewriteRule ^/(.*) /index.php/Main_Page [L] | RewriteRule ^/(.*) /index.php/Main_Page [L] | ||
− | + | RewriteCond %{REQUEST_URI} !^/(wiki|files)/ | |
− | + | RewriteRule ^/(.*) /index.php/$1 [L] | |
− | </pre> | + | </pre>}} |
+ | |||
+ | |||
The first condition and rule pair handles requests to the naked domain name and rewrites the to ''Main_Page'' so that the URL doesn't get appended with the "Main Page" name. The second pair says not to touch any URL's which start with ''/wiki/'' or ''/files/'', 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/files/math/ | The first condition and rule pair handles requests to the naked domain name and rewrites the to ''Main_Page'' so that the URL doesn't get appended with the "Main Page" name. The second pair says not to touch any URL's which start with ''/wiki/'' or ''/files/'', 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/files/math/ | ||
Line 17: | Line 15: | ||
$wgArticlePath = "/$1" | $wgArticlePath = "/$1" | ||
$wgScriptPath = '/wiki'; | $wgScriptPath = '/wiki'; | ||
+ | </php>}} | ||
+ | |||
− | |||
− | |||
It is set inside all default domains ''LocalSettings.php'' files through an include of a script called ''[[wikia.php]]'' (See [[Special:WikiaInfo]]) to make the friendly form the default way of rendering links. Links involving a query-string will use the usual format. | It is set inside all default domains ''LocalSettings.php'' files through an include of a script called ''[[wikia.php]]'' (See [[Special:WikiaInfo]]) to make the friendly form the default way of rendering links. Links involving a query-string will use the usual format. | ||
Line 31: | Line 29: | ||
*[http://www.mediawiki.org/wiki/Manual:Short_URL MediaWiki's manual entry] | *[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] | *[http://meta.wikimedia.org/wiki/Make_non-ugly_URLs WikiMedia article on freindly URL's] | ||
+ | [[Category:MediaWiki]] |
Revision as of 21:03, 29 June 2011
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:
The first condition and rule pair handles requests to the naked domain name and rewrites the to Main_Page so that the URL doesn't get appended with the "Main Page" name. The second pair says not to touch any URL's which start with /wiki/ or /files/, 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/files/math/
The re-write rule then assumes everything after the leading slash to be an article name and reformats the URL accordingly. Currently the only MediaWiki globals used for the rewrite rules is;
It is set inside all default domains LocalSettings.php files through an include of a script called wikia.php (See Special:WikiaInfo) to make the friendly form the default way of rendering links. Links involving a query-string will use the usual format.
Bug fixes
- Rewrite rules updated on 29 June 2011 to fix a long-standing bug preventing thumbnails from working for images with ampersands in their titles --nad 14:02, 29 June 2011 (PDT)
- Friendly URL's were updated again on 23 June 2007 to allow the main page to use the completely naked domain name --Nad 23:40, 23 June 2007 *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)
(NZST)