讓 MediaWiki 使用短網址(short url)

From Sevenjay's Wiki

Jump to: navigation, search

If you put a wiki in a subdirectory instead on the main site, but still want to have the Short URL work, you need to tweak the directions.

This modifies the .htaccess file and assumes that your web host does not have "AllowOverride None" specified for the server root (/).

Example URL: http://www.example.com/music/wiki/index.php?Title=Main_Page

Short URL: http://www.example.com/music/wiki/Main_Page

1. Edit or create .htaccess in public_html with the following content.
RewriteEngine On
RewriteBase /music
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wiki/(.*)$ ./wiki/index.php?title=$1 [PT,L,QSA]

'RewriteBase' defines where the rewrite will start; the example above will match after 'domain.ext/music'.

'RewriteCond' makes sure that links to files (like stylesheets or images) are not rewritten, which can break MediaWiki's formatting in some cases.

'RewriteRule' defines the rewrite; in the example above, '^wiki/(.*)' will invisibly load 'wiki/index.php?title=$1', where the page name after 'wiki/' will replace '$1'.

2. Add or edit the following setting in LocalSettings.php. This causes the HTML generated by MediaWiki to refer to "/wiki/Articlename" instead of the default.
$wgScriptPath = "/music/wiki";
$wgArticlePath = "$wgScriptPath/$1";

我的設定

1.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?title=$1 [PT,L,QSA]
2.
$wgScriptPath  = "";
$wgArticlePath = "$wgScriptPath/$1";
Personal tools