2013-02-28 67 views
0

大家都知道的Joomla与规范问题的一些相当大的问题,并没有真正解决这一问题的办法......我已经写了检查的URL代码和增加了相对=规范链接...PHP代码来解决问题,规范与Joomla

的代码是这样的:

<?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/">'; 
?> 

的作品,但我的问题是:

我有我的网站页面太多了,这如果声明将是疯狂的巨大

有没有办法将其转换为函数?那会从列表中读取网址?

类似:

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' 
} 

,并在一个循环槽全部负载榜单来看...

这是否有道理?还是我完全在这里?

欢呼声,丹

回答

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逻辑。它变成了一个直观的查找值。

+0

对不起,我想我忘了,更不用说我把这些代码在模板的index.php文件所以这段代码将,网站的每个网页上运行,这就是为什么我需要的if语句那里检查我们是什么页面在...上,并在页面上放置正确的规范链接。 – dan 2013-02-28 06:13:26

+0

@dan - 由于$ _SERVER [“REQUEST_URI”]部分,此代码将检查您所在的页面。尝试使用此代码并让我知道发生了什么。 – Aust 2013-02-28 06:16:43

+0

没有没有工作,所有我得到的每一页 <链接的rel =“规范” HREF以下链接=“http://domain.edu.au/”。$列表[$ _ SERVER [“REQUEST_URI “]]> – dan 2013-02-28 06:19:45