ねむすぎノート
トップ
メニュー
一覧
検索
🌙
pukiwiki1.5/redirect
をテンプレートにして作成
開始行:
* Pukiwiki内でリダイレクトしたい [#m66b4cc9]
#contents
** 経緯 [#zd53fcb2]
- Pukiwikiのページ名に自由に大文字を使ってしまっていたが...
> 大文字と小文字を混ぜてURLを設定することはできますが、ユ...
[[東京SEOメーカー:https://www.switchitmaker2.com/web-prod...
** 標準機能で実現 [#b090546b]
- 1.5.2からはリダイレクト機能が実装されていた。ありがたい...
`pukiwiki.ini.php` を編集する
#code_x{{
// Page redirect rules
$page_redirect_rules = array(
'#^Twitch/Yomiage#' => 'twitch/yomiage',
//'#^FromProject($|(/(.+)$))#' => 'ToProject$1',
//'#^FromProject($|(/(.+)$))#' => function($matches) { r...
);
}}
少なくとも[[TwitterでURL呟いた箇所:https://twitter.com/se...
ちなみにこのリダイレクト設定を行っても include には対応し...
#include(Parts/ThanksTerms,notitle)
** 設定を [[InterRedirect]] にまとめて追加できるようにす...
InterRedirectページに設定をまとめて、`pukiwiki.ini.php` ...
`pukiwiki.ini.php` の Page redirect rules 部分 を編集しま...
#code_x{{
/////////////////////////////////////////////////
// Page redirect rules loaded from InterRedirect
$page_redirect_rules = array();
/**
* InterRedirectページからサイト内リダイレクト設定を読み...
*
* 書式:
* -旧ページ => 新ページ
*
* 配下のページもまとめて転送:
* -旧カテゴリ/* => 新カテゴリ/*
*
* 外部URLは指定不可。
*/
function load_interredirect_rules($config_page = 'InterRe...
{
$rules = array();
/*
* PukiWikiのページ保存ファイル名を取得
*
* 通常はencode()を使用する。
* 万一この時点でencode()が未定義なら、
* UTF-8版PukiWiki用として16進数化する。
*/
if (function_exists('encode')) {
$encoded_page = encode($config_page);
} else {
$encoded_page = strtoupper(bin2hex($config_page));
}
$filename = DATA_DIR . $encoded_page . '.txt';
if (!is_file($filename) || !is_readable($filename)) {
return $rules;
}
$lines = file($filename, FILE_IGNORE_NEW_LINES);
if ($lines === false) {
return $rules;
}
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') {
continue;
}
// PukiWikiのコメント、見出し、プラグイン行を無視
if (
strpos($line, '//') === 0 ||
strpos($line, '*') === 0 ||
strpos($line, '#') === 0
) {
continue;
}
// リスト記号を除去
$line = preg_replace('/^[\-\+]+\s*/u', '', $line);
// 「旧ページ => 新ページ」に分割
$parts = preg_split('/\s*=>\s*/u', $line, 2);
if (count($parts) !== 2) {
continue;
}
$from = trim($parts[0]);
$to = trim($parts[1]);
if ($from === '' || $to === '') {
continue;
}
/*
* 外部URLを拒否
*
* 例:
* https://example.com/
* mailto:test@example.com
* //example.com/
*/
if (
preg_match('/^[a-z][a-z0-9+\-.]*:/i', $to) ||
strpos($to, '//') === 0
) {
continue;
}
/*
* 単純な自己リダイレクトを拒否
*
* PageA => PageA
*/
if ($from === $to) {
continue;
}
/*
* 配下ページをまとめて転送
*
* 例:
* elec2/* => electrical/*
*
* elec2/gakka
* ↓
* electrical/gakka
*/
if (
substr($from, -2) === '/*' &&
substr($to, -2) === '/*'
) {
$from_base = rtrim(substr($from, 0, -2), '/');
$to_base = rtrim(substr($to, 0, -2), '/');
if ($from_base === '' || $to_base === '') {
continue;
}
if ($from_base === $to_base) {
continue;
}
$pattern = '#^' . preg_quote($from_base, '#')...
/*
* クロージャーを使うことで、転送先ページ名に
* $ や \ が含まれても置換文字として誤解され...
*/
$rules[$pattern] = function ($matches) use ($...
return $to_base .
(isset($matches[1]) ? $matches[1] : '...
};
continue;
}
/*
* 片方だけ「/*」の場合は書式ミスとして無視
*/
if (
substr($from, -2) === '/*' ||
substr($to, -2) === '/*'
) {
continue;
}
// 通常ルールはページ名の完全一致
$pattern = '#^' . preg_quote($from, '#') . '$#u';
$rules[$pattern] = $to;
}
return $rules;
}
$page_redirect_rules = load_interredirect_rules('InterRed...
}}
#include(parts/feedback,notitle)
終了行:
* Pukiwiki内でリダイレクトしたい [#m66b4cc9]
#contents
** 経緯 [#zd53fcb2]
- Pukiwikiのページ名に自由に大文字を使ってしまっていたが...
> 大文字と小文字を混ぜてURLを設定することはできますが、ユ...
[[東京SEOメーカー:https://www.switchitmaker2.com/web-prod...
** 標準機能で実現 [#b090546b]
- 1.5.2からはリダイレクト機能が実装されていた。ありがたい...
`pukiwiki.ini.php` を編集する
#code_x{{
// Page redirect rules
$page_redirect_rules = array(
'#^Twitch/Yomiage#' => 'twitch/yomiage',
//'#^FromProject($|(/(.+)$))#' => 'ToProject$1',
//'#^FromProject($|(/(.+)$))#' => function($matches) { r...
);
}}
少なくとも[[TwitterでURL呟いた箇所:https://twitter.com/se...
ちなみにこのリダイレクト設定を行っても include には対応し...
#include(Parts/ThanksTerms,notitle)
** 設定を [[InterRedirect]] にまとめて追加できるようにす...
InterRedirectページに設定をまとめて、`pukiwiki.ini.php` ...
`pukiwiki.ini.php` の Page redirect rules 部分 を編集しま...
#code_x{{
/////////////////////////////////////////////////
// Page redirect rules loaded from InterRedirect
$page_redirect_rules = array();
/**
* InterRedirectページからサイト内リダイレクト設定を読み...
*
* 書式:
* -旧ページ => 新ページ
*
* 配下のページもまとめて転送:
* -旧カテゴリ/* => 新カテゴリ/*
*
* 外部URLは指定不可。
*/
function load_interredirect_rules($config_page = 'InterRe...
{
$rules = array();
/*
* PukiWikiのページ保存ファイル名を取得
*
* 通常はencode()を使用する。
* 万一この時点でencode()が未定義なら、
* UTF-8版PukiWiki用として16進数化する。
*/
if (function_exists('encode')) {
$encoded_page = encode($config_page);
} else {
$encoded_page = strtoupper(bin2hex($config_page));
}
$filename = DATA_DIR . $encoded_page . '.txt';
if (!is_file($filename) || !is_readable($filename)) {
return $rules;
}
$lines = file($filename, FILE_IGNORE_NEW_LINES);
if ($lines === false) {
return $rules;
}
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') {
continue;
}
// PukiWikiのコメント、見出し、プラグイン行を無視
if (
strpos($line, '//') === 0 ||
strpos($line, '*') === 0 ||
strpos($line, '#') === 0
) {
continue;
}
// リスト記号を除去
$line = preg_replace('/^[\-\+]+\s*/u', '', $line);
// 「旧ページ => 新ページ」に分割
$parts = preg_split('/\s*=>\s*/u', $line, 2);
if (count($parts) !== 2) {
continue;
}
$from = trim($parts[0]);
$to = trim($parts[1]);
if ($from === '' || $to === '') {
continue;
}
/*
* 外部URLを拒否
*
* 例:
* https://example.com/
* mailto:test@example.com
* //example.com/
*/
if (
preg_match('/^[a-z][a-z0-9+\-.]*:/i', $to) ||
strpos($to, '//') === 0
) {
continue;
}
/*
* 単純な自己リダイレクトを拒否
*
* PageA => PageA
*/
if ($from === $to) {
continue;
}
/*
* 配下ページをまとめて転送
*
* 例:
* elec2/* => electrical/*
*
* elec2/gakka
* ↓
* electrical/gakka
*/
if (
substr($from, -2) === '/*' &&
substr($to, -2) === '/*'
) {
$from_base = rtrim(substr($from, 0, -2), '/');
$to_base = rtrim(substr($to, 0, -2), '/');
if ($from_base === '' || $to_base === '') {
continue;
}
if ($from_base === $to_base) {
continue;
}
$pattern = '#^' . preg_quote($from_base, '#')...
/*
* クロージャーを使うことで、転送先ページ名に
* $ や \ が含まれても置換文字として誤解され...
*/
$rules[$pattern] = function ($matches) use ($...
return $to_base .
(isset($matches[1]) ? $matches[1] : '...
};
continue;
}
/*
* 片方だけ「/*」の場合は書式ミスとして無視
*/
if (
substr($from, -2) === '/*' ||
substr($to, -2) === '/*'
) {
continue;
}
// 通常ルールはページ名の完全一致
$pattern = '#^' . preg_quote($from, '#') . '$#u';
$rules[$pattern] = $to;
}
return $rules;
}
$page_redirect_rules = load_interredirect_rules('InterRed...
}}
#include(parts/feedback,notitle)
ページ名:
トップ
新規
一覧
検索
最終更新
RSS