MediaWikiで生成されるURLを短くする設定方法

提供: miniwiki
2018/7/21/ (土) 18:56時点におけるAdmin (トーク | 投稿記録)による版
移動先:案内検索


MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title=ページタイトル」のような形式で生成される。

ショートURLに変更する。

例えば「サンプル」というページを作る場合、このように変更する事ができる。


変更前
http://example.com/index.php?title=サンプル

変更後
http://example.com/サンプル

「LocalSettings.php」と「.htaccess」の2つのファイルに変更を加えます。

LocalSettings.phpにコード追記

MediaWikiのインストールしてあるフォルダにある「LocalSettings.php」に以下のコードを追記します。

$wgScript = "$wgScriptPath/index.php";
$wgRedirectScript = "$wgScriptPath/redirect.php";
$wgArticlePath = "$wgScriptPath/$1";

.htaccessにコード追記

同じくフォルダにある「.htaccess」に以下のコードを追記します。
.htaccessの最後尾は下に何もなくても改行して下さい。

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]

以上で作業完了。

「ドメイン/wiki/ページタイトル」のようにしたい場合

  • LocalSettings.php

$wgScriptPath = "/wiki";
$wgScript = "$wgScriptPath/index.php";
$wgRedirectScript = "$wgScriptPath/redirect.php";
$wgArticlePath = "$wgScriptPath/$1";

  • .htaccess

RewriteEngine on
RewriteBase /wiki/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]