「MediaWikiで生成されるURLを短くする設定方法」の版間の差分
提供: miniwiki
(ページの作成:「MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title=ページタイトル」のような形式で生成さ…」) |
細 |
||
(同じ利用者による、間の3版が非表示) | |||
1行目: | 1行目: | ||
− | MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title= | + | [[category:MediaWiki]] |
+ | |||
+ | MediaWikiでデフォルトの状態で新しいページを作ると、そのURLは「ドメイン/index.php?title=ページタイトル」のような形式で生成される。<br> | ||
ショートURLに変更する。<br> | ショートURLに変更する。<br> | ||
− | + | 例えば「サンプル」というページを作る場合、このように変更する事ができる。<br> | |
16行目: | 18行目: | ||
== LocalSettings.phpにコード追記 == | == LocalSettings.phpにコード追記 == | ||
MediaWikiのインストールしてあるフォルダにある「LocalSettings.php」に以下のコードを追記します。<br> | MediaWikiのインストールしてあるフォルダにある「LocalSettings.php」に以下のコードを追記します。<br> | ||
− | + | <syntaxhighlight> | |
− | $wgScript = "$wgScriptPath/index.php"; | + | $wgScript = "$wgScriptPath/index.php"; |
− | $wgRedirectScript = "$wgScriptPath/redirect.php"; | + | $wgRedirectScript = "$wgScriptPath/redirect.php"; |
− | $wgArticlePath = "$wgScriptPath/$1";< | + | $wgArticlePath = "$wgScriptPath/$1"; |
+ | </syntaxhighlight> | ||
== .htaccessにコード追記 == | == .htaccessにコード追記 == | ||
25行目: | 28行目: | ||
.htaccessの最後尾は下に何もなくても改行して下さい。<br> | .htaccessの最後尾は下に何もなくても改行して下さい。<br> | ||
− | RewriteEngine on | + | <syntaxhighlight> |
− | RewriteBase / | + | RewriteEngine on |
− | RewriteCond %{REQUEST_FILENAME} !-f | + | RewriteBase / |
− | RewriteCond %{REQUEST_FILENAME} !-d | + | RewriteCond %{REQUEST_FILENAME} !-f |
− | RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]< | + | RewriteCond %{REQUEST_FILENAME} !-d |
+ | RewriteRule ^(.+)$ index.php?title=$1 [L,QSA] | ||
+ | </syntaxhighlight> | ||
以上で作業完了。 | 以上で作業完了。 | ||
+ | |||
+ | == 「ドメイン/wiki/ページタイトル」のようにしたい場合 == | ||
+ | * LocalSettings.php | ||
+ | <syntaxhighlight> | ||
+ | $wgScriptPath = "/wiki"; | ||
+ | $wgScript = "$wgScriptPath/index.php"; | ||
+ | $wgRedirectScript = "$wgScriptPath/redirect.php"; | ||
+ | $wgArticlePath = "$wgScriptPath/$1"; | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | * .htaccess | ||
+ | <syntaxhighlight> | ||
+ | RewriteEngine on | ||
+ | RewriteBase /wiki/ | ||
+ | RewriteCond %{REQUEST_FILENAME} !-f | ||
+ | RewriteCond %{REQUEST_FILENAME} !-d | ||
+ | RewriteRule ^(.+)$ index.php?title=$1 [L,QSA] | ||
+ | </syntaxhighlight> |
2018/7/21/ (土) 19:09時点における最新版
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]