引っ越し用スクリプト
2006年3月16日
汎用的な、『このページは移動しました』表示スクリプトを書いてみた。mod_rewrite対応。
<?php $url='http://www.rad51.net/'; // Resolve directory name $site=realpath('index.php'); $site=preg_replace('/\/index.php$/','',$site); while (($i=strpos($site,'/'))!==false) $site=substr($site,$i+1); $url=$url.$site.'/'; // Resolve URI $page=$_SERVER['REQUEST_URI']; $page=preg_replace('/^[\s]*?\/'.$site.'\//','',$page); $page=preg_replace('/^archive-([0-9]+)-([0-9]+)-([0-9]+).html/','index.php?archive=$2-$3&blogid=$1',$page); $page=preg_replace('/^item-([0-9]+).html/','index.php?itemid=$1',$page); $page=preg_replace('/^archivelist-([0-9]+).html/','index.php?archivelist=$1',$page); $page=preg_replace('/^trackback-([0-9]+).html/','action.php?action=plugin&name=TrackBack&tb_id=$1',$page); // Create new URL if (preg_match ('/^[a-z]+\.php/',$page)) $url.=$page; // Check lanuage if (strpos(strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']),'ja')===0) { $charset='EUC-JP'; } else { $charset='iso-8859-1'; } header("Content-Type: text/html; charset=$charset"); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Moved</title> <meta http-equiv="refresh" content="5; url=<?php echo $url; ?>" /> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" /> <style type="text/css"> body { color: #D00000; background: #ffffff; text-align: center; } </style> </head><body><div> <?php if ($charset=='EUC-JP') { ?> <h4>このページは、以下のアドレスに移動しました。</h4> <a href="<?php echo $url; ?>"><?php echo $url; ?></a> <h4>5秒後に自動的にジャンプします。<br /> しない場合は、上記のアドレスをクリックしてください。</h4> <?php } else { ?> <h4>This page has been moved to:</h4> <a href="<?php echo $url; ?>"><?php echo $url; ?></a> <h4>The browser will go to new page in 5 seconds automatically.<br /> If does not, please click the address above.</h4> <?php }?> </div></body></html>