text links for sale

Thursday, November 3, 2011

วิธีเปลี่ยน domain ของ wpmu โดยไม่ต้อง install ใหม่ (how to change domain name wordpress multisite without re-install )

คำเตือน   warning

1. ควร backup database   (backup database )

2. ควรเป็นผู้ชำนาญการใช้งาน phpmyadmin  (you must expert in phpmyadmin )

3. ร้ายแรงมากถ้าทำพัง ดังนั้นควรลองกับโดเมนที่โดนแบนจริงๆแล้วเท่านั้น (testing before do it with your production website)

ข้อมูลอ้างอิง (reference)  http://borism.net/2008/12/02/c...senvironments-in-wordpress-mu/

pre

-ทำการ point domain ใหม่ มาที่ host ที่ต้องการเปลี่ยนโดเมน   (Poin new domain name to your hosting  name server )



-ทำการ addon domain ใหม่ โดยให้ path ชี้มาที่ path ของ domain เก่า เช่น   ใหม่.com  ชี้ path ไปที่   /public_html/เก่า.com  (in cpanel addon new domain and setting directory path to old wordpress multisite directory path )

-ทำ การ wildcard subdomain ใหม่ โดยให้ชี้มาที่ path ของ domain เก่า เช่นกัน  เช่น  *.ใหม่.com    ชี้ path ไปที่   /public_html/เก่า.com  (wildcard subdomain to old wordpress multisite directory path )


เตรียมสคริปดังนี้  (prepare this script and save in php files  run in root directory of old domain)

<?php
require_once('wp-load.php');
 
$querystr ="SHOW TABLES LIKE 'wp_%_options'";
$tables = $wpdb->get_results($querystr, ARRAY_N);
echo count($tables);
$query = "";
if ($tables){
 foreach ($tables as $table){
  echo $table[0];
  $query = 'UPDATE '.$table[0].' SET option_value = REPLACE(option_value,"ชื่อโดเมนเก่า","ชื่อโดเมนใหม่")';
  $wpdb->query($query);
 }
}
?>
 

ในโค้ดนี้ไปเซฟ เป็นไฟล์ php ชื่ออะไรก้อได้ แล้วไปวางที่ root path ของโดเมนที่โดนแบนไปแล้ว
ทำการรัน

2. เข้าไปที่ php myadmin เพื่อเข้าถึง database ของ wpmu ต้นปัญหา (ถ้าไม่รู้ว่า database ตัวไหน เปิดดูที่ wp-config.php )    go to  phpmyadmin  if you install wordpress with automatic script open wp-config.php to see name of your database name

3. รันสคริป ตัวนี้ ที่ตรง sql  
UPDATE wp_blogs SET domain = REPLACE(domain,'ชื่อโดเมนเก่า','ชื่อโดเมนใหม่')

run this script

update wp_blogs set domain = REPLACE(domain,'your old domain' ,'your new domain')

4. เข้าไปที่ table wp_options  

ไปแก้ field option_value ที่ยังเป็นชื่อโดเมนเก่าอยู่ ที่มี option_name = siteurl ,  blogname , home
ควรแก้อย่างเบามือ เพราะมันเยอะ และ ตาลาย แก้ด้วยมือ น่าจะดีกว่า sql นะ สำหรับ table นี้

edit table wp_options  : field option_value  and other field that have old domain name

5 อย่าลืมไปแก้ไฟล์ wp-config.php

edit wp-config.php change new domain name in that files



forum links