Difference between revisions of "Friendly URL's"

From Organic Design wiki
(update description of rules)
m
 
(2 intermediate revisions by 2 users not shown)
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 in our [[Subversion]] repository in the [http://svn.organicdesign.co.nz/filedetails.php?repname=tools&path=%2Fwiki.vhost wiki.vhost] file which is directly included by our Apache configuration, and contains the following:
+
{{legacy}}
{{code|<pre>
+
We used to 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 in our [[Subversion]] repository in the [http://svn.organicdesign.co.nz/filedetails.php?repname=tools&path=%2Fwiki.vhost wiki.vhost] file which is directly included by our Apache configuration, and contains the following:
 +
<source lang="apache">
 
RewriteCond %{REQUEST_URI} ^/$
 
RewriteCond %{REQUEST_URI} ^/$
 
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
 
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
Line 18: Line 19:
 
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
 
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
 
RewriteRule (.*) /%2/wiki/index.php$1 [L]
 
RewriteRule (.*) /%2/wiki/index.php$1 [L]
</pre>}}
+
</source>
  
  
Line 24: Line 25:
  
 
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;
 
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;
{{code|<php>
+
<source lang="php">
 
$wgArticlePath = "/$1"
 
$wgArticlePath = "/$1"
 
$wgScriptPath  = '/wiki';
 
$wgScriptPath  = '/wiki';
</php>}}
+
</source>
  
  
Line 36: Line 37:
 
*Friendly URL's were updated again on [[23 June 2007]] to allow the main page to use the completely naked domain name --[[User:Nad|Nad]] 23:40, 23 June 2007 *It was transforming to <tt>...index.php?title=$1</tt>, but this cause the ampersand bug, see [[17 February 2007]] news item.
 
*Friendly URL's were updated again on [[23 June 2007]] to allow the main page to use the completely naked domain name --[[User:Nad|Nad]] 23:40, 23 June 2007 *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)
 
*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)
(NZST)
 
  
 
== See also ==
 
== See also ==
 +
*[[Nginx]] ''- we now use the Nginx web-server''
 
*[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]]
 
[[Category:MediaWiki]]

Latest revision as of 17:57, 22 May 2015

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, this is only useful for a historic record of work done. You may find a link to the currently used concept or function in this article, if not you can contact the author to find out what has taken the place of this legacy item.

We used to 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 in our Subversion repository in the wiki.vhost file which is directly included by our Apache configuration, and contains the following:

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
RewriteRule .* /%2/wiki/index.php?title=Main_Page&redirect=no [L]

RewriteCond %{REQUEST_URI} ^/files/thumb/./../.*\&
RewriteRule ^(.*?)\&(.*)$ $1\%26$2

RewriteCond %{REQUEST_URI} ^/files/thumb/./../.+?/[0-9]+px-
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
RewriteRule ^.+/(.+?)/([0-9]+)px- /%2/wiki/thumb.php?w=$2&f=$1 [L]

RewriteCond %{REQUEST_URI} ^/(wiki/|html/|files/|common/|blogs|[fF]avicon.ico|[rR]obots.txt)
RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
RewriteRule (.*) /%2$1 [L]

RewriteCond %{HTTP_HOST} ^(www\.|wiki\.)?(.+)$
RewriteRule (.*) /%2/wiki/index.php$1 [L]


The first section handles requests to the naked domain name and rewrites them to Main_Page so that the URL doesn't get appended with the "Main Page" name. The second pair fixes the ampersand problem in thumbnails. The third rewrites the thumbnail URL's so that arbitrary sizes of image thumbnails can be dynamically requested from the MediaWiki thumb.php script. The forth allows certain directories not to be rewritten such as those containing scripts or files. And finally the fifth section rewrites the friendly article format of URLs to the internal format including index.php'.

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;

$wgArticlePath = "/$1"
$wgScriptPath  = '/wiki';


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)

See also