WPML

ภาพรวมของปัญหา

ผู้ใช้ที่ติดตั้ง WordPress ในโฟลเดอร์ย่อยและใช้ฟีเจอร์ ใช้ไดเรกทอรีสำหรับภาษาเริ่มต้น ของ WPML จะพบปัญหาการสร้าง URL ที่ไม่ถูกต้องสำหรับหน้าคลังเก็บของอนุกรมวิธานและลิงก์ประเภทโพสต์แบบกำหนดเอง ซึ่งส่งผลให้เกิดพาธซ้ำซ้อนใน URL และทำให้เกิดข้อผิดพลาด 404 ตามมาเมื่อพยายามเข้าถึงหน้าเหล่านี้

ตัวอย่างเช่น คุณจะถูกเปลี่ยนเส้นทางไปยัง http://www.domain.com/subfolder/en/subfolder/en/category/new-category/ แทนที่จะเป็น http://www.domain.com/subfolder/en/category/new-category/

วิธีแก้ปัญหาชั่วคราว

ปัญหานี้ได้รับการแก้ไขแล้วใน WPML 4.6.9 การอัปเดตจะแก้ปัญหานี้บนไซต์ของคุณ ดังนั้นคุณจึงต้องใช้วิธีแก้ปัญหาชั่วคราวนี้เฉพาะเมื่อคุณยังไม่สามารถอัปเดตได้

โปรดตรวจสอบให้แน่ใจว่าได้สำรองข้อมูลทั้งหมดของไซต์ก่อนดำเนินการต่อ

  • เปิดไฟล์ …/wp-content/plugins/sitepress-multilingual-cms/classes/canonicals/class-wpml-canonicals-hooks.php
  • ค้นหาบรรทัดที่ 87
  • เปลี่ยน:
    public function redirectArchivePageToDefaultLangDir() {
    	global $wp_query;
    
    	$isValidForRedirect = $wp_query->is_archive() && ! call_user_func( $this->is_current_request_root_callback );
    
    	if ( ! $isValidForRedirect ) {
    		return;
    	}
    
    	$currentUri = $_SERVER['REQUEST_URI'];
    	$lang       = $this->sitepress->get_current_language();
    
    	if ( 0 !== strpos( $currentUri, '/' . $lang ) ) {
    		$canonicalUri = user_trailingslashit(
    			$this->url_converter->get_abs_home() . '/' . $lang . $currentUri
    		);
    
    		$this->redirectTo( $canonicalUri );
    	}
    }
    
    private function redirectTo( $uri ) {
    	$this->sitepress->get_wp_api()->wp_safe_redirect( $uri, 301 );
    }
  • เป็น:
    public function redirectArchivePageToDefaultLangDir() {
    	global $wp_query;
    
    	$isValidForRedirect = $wp_query->is_archive() && ! call_user_func( $this->is_current_request_root_callback );
    
    	if ( ! $isValidForRedirect ) {
    		return;
    	}
    
    	$currentUri = $_SERVER['REQUEST_URI'];
    	$lang       = $this->sitepress->get_current_language();
    
    	if ( 0 !== strpos( $currentUri, '/' . $lang ) ) {
    		$realhome = get_option('siteurl');
    		$parsed = parse_url($realhome);
    		if (false !== strpos($currentUri, $parsed["path"])){
    			return;
    		} else {
    		$canonicalUri = user_trailingslashit(
    			$this->url_converter->get_abs_home() . '/' . $lang . $currentUri
    		);
    		}
    
    		$this->redirectTo( $canonicalUri );
    	}
    }

ปัญหาที่ทราบแล้วทั้งหมด

ยังคงพบปัญหานี้อยู่หรือไม่

หากการอัปเดตไม่สามารถแก้ไขปัญหานี้ได้ ส่งคำถามถึงฝ่ายสนับสนุน และเราจะตรวจสอบร่วมกับคุณ