- الحالة
- محلولة
- تم حلها في
- 3.7.0
نظرة عامة على المشكلة
منذ WPML 3.6.3، يواجه بعض المستخدمين عمليات إعادة توجيه غير صحيحة للمتصفح عند ضبط تنسيق عنوان URL للغة في صفحة WPML -> اللغات بالإعدادات التالية:
- لغات مختلفة في أدلة
- استخدام الدليل للغة الافتراضية => مُمكّن
حل بديل مؤقت
سيتم حل هذه المشكلة في إصدار WPML التالي.
في غضون ذلك، لدينا تصحيح يمكنك تطبيقه على ملف class-wpml-canonicals-hooks.php، الموجود في مجلد ../wp-content/plugins/sitepress-multilingual-cms/classes/canonicals/.
استبدل كتلة الكود الكاملة التالية، في السطر 34 تقريباً:
public function redirect_pages_from_root_to_default_lang_dir() {
if ( is_page() ) {
$current_path = wpml_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$canonical_url = get_permalink( get_queried_object_id() );
$canonical_path = wpml_parse_url( $canonical_url, PHP_URL_PATH );
$canonical_path = $this->get_paginated_canonical_path( $canonical_path );
if ( $current_path !== $canonical_path ) {
$current_query = wpml_parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY );
parse_str( $current_query, $current_query_array );
$canonical_url = add_query_arg( $current_query_array, $canonical_url );
$this->sitepress->get_wp_api()->wp_safe_redirect( $canonical_url, 301 );
}
}
}
بـ:
public function redirect_pages_from_root_to_default_lang_dir() {
global $wpml_url_converter;
if ( is_page() && ! WPML_Root_Page::is_current_request_root() ) {
$lang = $this->sitepress->get_current_language();
$current_uri = $_SERVER['REQUEST_URI'];
$abs_home = $wpml_url_converter->get_abs_home();
$install_subdir = wpml_parse_url( $abs_home, PHP_URL_PATH );
$actual_uri = preg_replace( '#^' . $install_subdir . '#', '', $current_uri );
$actual_uri = '/' . ltrim( $actual_uri, '/' );
if ( 0 !== strpos( $actual_uri, '/' . $lang . '/' ) ) {
$canonical_uri = trailingslashit( $install_subdir ) . $lang . $actual_uri;
$canonical_uri = user_trailingslashit( $canonical_uri );
$this->sitepress->get_wp_api()->wp_safe_redirect( $canonical_uri, 301 );
}
}
}