Mw:Short URL

From Kb_JMY(晉明夷)

Jump to: navigation, search
  • Mediawiki: Short_URL


Making Short_URL for "Actions"

  • Ref:
  1. mediawiki.org: $wgActionPaths
  2. mediawiki.org: Short_URL
  3. mwusers.com: Failed to make Short URLs for actions such as "edit" by $wgActionPaths, pls. help!
  4. GreenHost ticket support 2007/11/13 17:03 (GMT+8) with title "URL rewrite for subdomain access -> edit failed, pls. help!"


  • Assumes:
  1. wiki is accessed by ------------- http://kb.mysite.org
  2. wiki installation directory -- "public_html/kb"
  3. LocalSettings.php ------------ $wgScriptPath=""; //Note: not [ $wgScriptPath="/kb"; ] as subdomain access!
  4. URL before rewrite ------- http://kb.mysite.org/index.php/MwDoc
  5. Want URL after rewrite --- http://kb.mysite.org/wiki/MwDoc


Procedures

  • Step01: ".htaccess" file -- Rewrite URL for all "Actions" (e.g. view, edit, submit,...)
  • RewriteRule ^/action/([a-z]*)/(.*)$ /index.php?action=$1&title=$2 [L,QSA]
  • This will forward all requests to "/action/actionword/title " to "index.php?action=actionword&title=title"
  • The complete ".htaccess" file should look like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$  /index.php?title=$1 [L,QSA]
RewriteRule ^/action/([a-z]*)/(.*)$ /index.php?action=$1&title=$2 [L,QSA]
  • Note: line3 is "/index.php?title=$1" and not "/kb/index.php?title=$1"
  • Put the ".htaccess" file in "public_html/kb":


  • Step02: LocalSettings.php -- add "$wgArticlePath" & "$wgActionPaths"
  • Add the following lines to LocalSettings.php :
$actions = array('view', 'edit', 'watch', 'unwatch', 'delete','revert', 'rollback', 'protect',
'unprotect','info','markpatrolled','validate','render','deletetrackback','print',
'dublincore','creativecommons','credits','submit','viewsource','history','raw',
'purge');

foreach ($actions as $a) $wgActionPaths[$a] = "$wgScriptPath/wiki/$a/$1";

$wgArticlePath = "$wgScriptPath/wiki/view/$1";
  • After that we can have URL like these:



Personal tools