WPML
ステータス
開発者からの返答待ち
報告対象
WPML SEO 2.1.0
関連するプラグイン/テーマ
Yoast SEO
トピックタグ
Compatibility

問題の概要

Yoast SEO Proプラグインを使用する場合、RegExのリダイレクトルールは異なる言語間で同じようには機能しません。デフォルト言語と第2言語とでは動作が異なります。

たとえば、^/en/faq/(.+)$から/en/support/$1, へのリダイレクトルールを作成した場合、http://example.com/en/faq/test/経由でアクセスしようとすると、期待どおりに機能しない場合があります。

回避策

オプション1


簡単な回避策として、異なるルールを作成できます。
最初の例に従うと以下のようになります。

  • ^/faq/(.+)$ は /support/$1 にリダイレクトします

  • ^faq/(.+)$ は /en/support/$1 にリダイレクトします

オプション2


続行する前に、サイトの完全なバックアップを取得していることを確認してください。

  • …/wp-content/plugins/wp-seo-multilingual/classes/class-wpml-wpseo-redirection.phpファイルを開きます。

  • 34行目を探します。

  • 以下のコードを:
    foreach ( $redirections as $redirection ) {
        if ( $redirection['origin'] === $url || '/' . $redirection['origin'] === $url ) {
            return true;
        }
    }


  • 次のコードに置き換えます:
    foreach ( $redirections as $redirection ) {
    				if($redirection['format'] == 'regex'){
    					// Ensure $url starts with /, if regex would need to check if string starts with this is needed.
    					if(strpos($url, '/', 0) !== 0){
    						$url = '/' . $url;
    					}
    					// Lets use ~ as a regex delimiter instead of /, as we are matching a URL.
    					preg_match('~' . $redirection['origin'] . '~', $url, $matches); 
    					if(count($matches) > 0){
    						return true;
    					}
    				} else if($redirection['origin'] === $url || '/' . $redirection['origin'] === $url){
    					return true;
    				}
    }

すべての既知の問題 →