「MediaWikiで生成されるURLを短くする設定方法」の版間の差分
(ページの作成:「MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title=ページタイトル」のような形式で生成さ…」) |
細 |
||
1行目: | 1行目: | ||
− | MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title= | + | MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title=ページタイトル」のような形式で生成される。<br> |
ショートURLに変更する。<br> | ショートURLに変更する。<br> | ||
− | + | 例えば「サンプル」というページを作る場合、このように変更する事ができる。<br> | |
32行目: | 32行目: | ||
以上で作業完了。 | 以上で作業完了。 | ||
+ | |||
+ | == 「ドメイン/wiki/ページタイトル」のようにしたい場合 == | ||
+ | * LocalSettings.php | ||
+ | |||
+ | $wgScriptPath = "/wiki";<br> | ||
+ | $wgScript = "$wgScriptPath/index.php";<br> | ||
+ | $wgRedirectScript = "$wgScriptPath/redirect.php";<br> | ||
+ | $wgArticlePath = "$wgScriptPath/$1";<br> | ||
+ | |||
+ | * .htaccess | ||
+ | |||
+ | RewriteEngine on<br> | ||
+ | RewriteBase /wiki/<br> | ||
+ | RewriteCond %{REQUEST_FILENAME} !-f<br> | ||
+ | RewriteCond %{REQUEST_FILENAME} !-d<br> | ||
+ | RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]<br> |
2018/7/21/ (土) 18:55時点における版
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]