ฉันย้าย approx 100 บทความจากของฉันเก่าของเว็บไซต์ของเพื่อนใหม่ ฉันอยากจะสร้างเปลี่ยนปลายทางจดหมายในคนเก่าของเว็บไซต์เป็นส่วนหัวดังนั้นถ้าคนเก่าที่อยู่ URL ของบทความน่าจะไปเยี่ยม,คนที่มาเยี่ยมเธอควรจะ redirected ใหม่ที่อยู่ URL ของบทความนั่น
อย่างไรก็ตามออกแค่จะติดแทนที่ลงโดเมนจะไม่ทำอย่างเทคนิคอย่างที่ฉันเปลี่ย permalink ของข่าว. ดังนั้น ฉันคงต้องการ"ลอกฐานข้อมูล"(กับ arrays?) ซึ่งจะต้องตัดสินใจถ้าคนจริงที่อยู่ URL ที่มีเปลี่ยนปลายทางจดหมายในฐานข้อมูลแบบ:
// "the old permalink" = "the new permalink"
$urlpermalink["article-cars"] = "http://NewWebsite.com/new-cars-article";
$urlpermalink["an-article-dogs"] = "http://NewWebsite.com/new-dogs-text";
$urlpermalink["old-text-trees"] = "http://NewWebsite.com/new-blogcontent-about-trees";
ดังนั้นสำหรับตัวอย่างเช่นถ้ามีแขกที่มาเยี่ยม"http://OldWebsite.com/article-cars"เขาควรจะ redirected ต้อง"http://NewWebsite.com/new-cars-article"เพราะนั่นเป็นวิธีของฐานข้อมูล/อาเรย์บอก
และผมจะได้อะไรแบบนี้:
$visitingurl = $_SERVER[REQUEST_URI]; // Getting the URL the visitor is on now
foreach( $urlpermalink as $value ) { // For every entry in the database/array...
if (strpos($visitingurl, $urlpermalink) !== false) { // check if the visitingurl contains that (like "article-cars")
// The visitor is indeed on an old URL which is in the database/array, so let's redirect him to the new URL
header("HTTP/1.1 301 Moved Permanently");
header(url . $_SERVER['QUERY_STRING']);
exit();
}
}
แน่นอนนี่คือรหัสนผิดแต่ฉันต้องเกือบจะไม่มีความคิดเรื่อง PHPดังนั้นคุณช่วยได้โปรดช่วยฉันแก้ไขเรื่องนี้? (เป็น จาวาสคริปต์-ทางออกก็ดีเหมือนกันหรือ htaccessหรืออะไรก็ตามที่:))
ขอบคุณมากครับ!