正如你所见,我换域名了,cn->net。换域名会带来各种问题,比如原来的域名和链接都不能用了,尤其是你的就域名快要废弃或者被废弃时,你不得不通知各种各样的人或者机器(比如Google bot)你的域名已经改变了,就的域名很快就失效了。
当然对于人,这个插件不能帮你解决什么问题,不过对于机器就不同了。简单的讲插件的目的是将使用旧域名访问的所有流量通过HTTP 301 永久重定向到新域名,前提是目录结构仍然相同,如果想要进行更加精确的重定向,还是用htaccess文件吧。(注意,在WP的后台设置新的域名还是需要的)
<?php /* Plugin Name: WP-RedirectEx Plugin URI: http://blog.icybear.net/2009/12/wp-plug-ins-to-replace-the-domain-name.htm Description: Redirect to a different domain Version: 0.1 Author: Bearice Author URI: http://blog.icybear.net/ */ add_action('init', 'wrex_init'); function wrex_init(){ add_option('wrex_hostname', $_SERVER['HTTP_HOST']); $host = get_option('wrex_hostname'); if($_SERVER['HTTP_HOST']==$host ||strstr($_SERVER['REQUEST_URI'],"/wp-admin") ||strstr($_SERVER['REQUEST_URI'],"/wp-login")){ return; } header("HTTP/1.1 301 Moved Permanently"); header("Location: http://".$host.$_SERVER['REQUEST_URI']); exit(0); } add_action('admin_menu','wrex_admin_menu'); function wrex_admin_menu(){ add_submenu_page('options-general.php','WP-RedirectionEx Options','WP-RedirectionEx Options',8,'wrex','wrex_admin_page'); } function wrex_admin_page(){ if( $_POST['wrex_submit']) { update_option( 'wrex_hostname' , $_POST['wrex_hostname'] ); ?> <div class="updated"><p><strong><?php echo _e('Options saved.', 'wrex' ); ?></strong></p></div> <?php } ?> <div class="wrap"> <h2><? _e( 'WP-RedirectionEx Options', 'wrex' ); ?></h2> <form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>"> <input type="hidden" name="wrex_submit" value="true"> <p> <?php _e("Host Name:", 'wrex' ); ?> <input type="text" name="wrex_hostname" value="<?php echo get_option('wrex_hostname'); ?>" size="60"> </p> <p class="submit"> <input type="submit" name="Submit" value="<?php _e('Update Options', 'wrex' ) ?>" /> </p> </form> </div> <?php } ?>
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; zh-CN; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6
我偷懒,直接去改wp-blog-header.php…