Skip to content

Instantly share code, notes, and snippets.

@yoshuki
Created January 4, 2009 12:39
Show Gist options
  • Save yoshuki/43044 to your computer and use it in GitHub Desktop.
Save yoshuki/43044 to your computer and use it in GitHub Desktop.
<?php
/** WordPressの設定ファイル */
require_once('wp-config.php');
$db = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
mysql_select_db(DB_NAME, $db);
$sql = "SELECT post_date, post_name FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
$pn = $row['post_name'];
$pd = strtotime($row['post_date']);
// パスのみ
$from = '/weblog/' . date('Y/m/', $pd) . $pn . '.html';
// フルURL
$to = 'http://example.com/weblog/' . date('/Y/m/d/His', $pd) . '.html';
echo 'Redirect permanent ' . $from . ' ' . $to . "\n";
}
mysql_close($db);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment