「MediaWikiで生成されるURLを短くする設定方法」の版間の差分

提供: miniwiki
移動先:案内検索
18行目: 18行目:
 
== LocalSettings.phpにコード追記 ==
 
== LocalSettings.phpにコード追記 ==
 
MediaWikiのインストールしてあるフォルダにある「LocalSettings.php」に以下のコードを追記します。<br>
 
MediaWikiのインストールしてあるフォルダにある「LocalSettings.php」に以下のコードを追記します。<br>
 
+
<syntaxhighlight>
$wgScript          = "$wgScriptPath/index.php";<br>
+
$wgScript          = "$wgScriptPath/index.php";
$wgRedirectScript  = "$wgScriptPath/redirect.php";<br>
+
$wgRedirectScript  = "$wgScriptPath/redirect.php";
$wgArticlePath      = "$wgScriptPath/$1";<br>
+
$wgArticlePath      = "$wgScriptPath/$1";
 +
</syntaxhighlight>
  
 
== .htaccessにコード追記 ==
 
== .htaccessにコード追記 ==
27行目: 28行目:
 
.htaccessの最後尾は下に何もなくても改行して下さい。<br>
 
.htaccessの最後尾は下に何もなくても改行して下さい。<br>
  
RewriteEngine on<br>
+
<syntaxhighlight>
RewriteBase /<br>
+
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f<br>
+
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d<br>
+
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]<br>
+
RewriteCond %{REQUEST_FILENAME} !-d
 +
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]
 +
</syntaxhighlight>
  
 
以上で作業完了。
 
以上で作業完了。
37行目: 40行目:
 
== 「ドメイン/wiki/ページタイトル」のようにしたい場合 ==
 
== 「ドメイン/wiki/ページタイトル」のようにしたい場合 ==
 
* LocalSettings.php
 
* LocalSettings.php
 
+
<syntaxhighlight><syntaxhighlight>
$wgScriptPath    = "/wiki";<br>
+
$wgScriptPath    = "/wiki";
$wgScript          = "$wgScriptPath/index.php";<br>
+
$wgScript          = "$wgScriptPath/index.php";
$wgRedirectScript  = "$wgScriptPath/redirect.php";<br>
+
$wgRedirectScript  = "$wgScriptPath/redirect.php";
$wgArticlePath      = "$wgScriptPath/$1";<br>
+
$wgArticlePath      = "$wgScriptPath/$1";
 +
</syntaxhighlight>
  
 
* .htaccess
 
* .htaccess
 
+
<syntaxhighlight>
RewriteEngine on<br>
+
RewriteEngine on
RewriteBase /wiki/<br>
+
RewriteBase /wiki/
RewriteCond %{REQUEST_FILENAME} !-f<br>
+
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d<br>
+
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]<br>
+
RewriteRule ^(.+)$ index.php?title=$1 [L,QSA]
 +
</syntaxhighlight>

2018/7/21/ (土) 19:08時点における版


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
<syntaxhighlight>
$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]