0

私たちは皆、joomlaが標準的な問題でいくつかのかなり大きな問題を抱えていることを知っていますが、実際にはこの問題に対処する方法ではありません...私はURLをチェックしてrel = canonicalリンクを追加するコードを書きました...

コードは次のようになります。

<?php 
$canonicalLink =  "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"]; 
if ($canonicalLink == 'http://domain.edu.au/index.php')
echo '<link rel="canonical" href="http://domain.edu.au/">';
if ($canonicalLink == 'http://domain.edu.au/?view=featured')
echo '<link rel="canonical" href="http://domain.edu.au/">';
?>

それは機能しますが、私の問題は次のとおりです。

私のウェブサイトにはページが多すぎて、この if ステートメントは非常に巨大になります

これを関数に変換する方法はありますか?リストからURLを読み取りますか?

何かのようなもの:

list:

http://domain.edu.au/?view=featured | http://domain.edu.au/
http://domain.edu.au/?view=contact | http://domain.edu.au/contact-us
http://domain.edu.au/?view=about | http://domain.edu.au/about-us
http://domain.edu.au/category-a/subcategory-a | http://domain.edu.au/category-main/subcategory-main

関数:

function (a | b){
if (a)
echo 'b'
}

そして、ロード時にすべてのリストをループしてこれを実行します...

これは意味がありますか?それとも私はここから完全に離れていますか?

乾杯、ダン

4

1 に答える 1

0

次のようなことができます。

//populate $list with the end of the actual uri as the key
//and what you want the actual uri to be as the value
$list = array(
  '/index.php'=>'',
  '/?view=featured'=>'',
  '/?view=contact'=>'contact-us',
  '/?view=about'=>'about-us',
  '/category-a/subcategory-a'=>'category-main/subcategory-main'
);

echo '<link rel="canonical" href="http://domain.edu.au/'.$list[$_SERVER["REQUEST_URI"]].'">';

ifこれにより、ロジックを実行する必要がなくなります。そのままルックアップ値になります。

于 2013-02-28T06:02:29.030 に答える