我工作的公司通过跟踪他们的第三方网站链接到合作伙伴。因此,例如在我们的网站上,将有一个类似这样的传出链接(名称已更改以保护我的工作):
<a href="link.php?link=chuckecheese">check it out kids!</a>
如果你进入 link.php,你会看到我在那里定义了链接:
$outlink['chuckecheese'] = "http://partners.linktrackingisprettycool.com/x/212/CD1/$STAMP";
$STAMP 是一个时间戳,在圣诞节中午被替换为“12-25-09-1200”。
当用户单击此链接时,他会转到 www.chuckecheese.com
这一切都很好,但对于 SEO 目的而言,它并没有达到应有的效果。我想让搜索引擎将其视为指向 chuckecheese.com 的链接,这有助于我们合作伙伴的网页排名并且更加诚实。
我在 .htaccess 中试图制定重写规则,但我很困惑并且不知道它是如何完成的。我试过:
RewriteRule http://www.chuckecheese.com$ link.php?link=chuckecheese$ [QSA]
但这似乎行不通。接下来我应该尝试什么?
在此先感谢您的帮助。你们这里的人总是很棒,我很感激 stack overflow 的好人在我保持就业方面发挥的作用。
最佳答案
您不能为此使用重写规则来重定向用户。该请求必须是由您的网络服务器处理的请求。
您可以尝试使用一些 javascript 来实现这一点。所以 href 是 chuckecheese,但是单击时,您将 document.location 更改为您真正想做的。
已编辑赏金问题
您可以做的是根据浏览器的用户代理预处理您的链接。因此,当用户代理是 googlebot(以下字符串之一)时,您会显示 http://www.chuckecheese.com 的真实网址.
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Googlebot/2.1 (+http://www.googlebot.com/bot.html)
Googlebot/2.1 (+http://www.google.com/bot.html)
当 URL 不是 googlebot 时,您会显示进行流量分析的链接。
您可以在以下 URL 中找到用户代理列表:
- http://www.useragentstring.com/Googlebot2.1_id_71.php
- http://www.user-agents.org/
- http://www.pgts.com.au/pgtsj/pgtsj0208c.html
如果 googlebot 没有显示正确的用户代理(或者它在未来发生变化),google 建议您对 IP 地址进行反向查找。这将对性能造成很小的影响。
You can verify that a bot accessing your server really is Googlebot by using a reverse DNS look up, verifying that the name is in the googlebot.com domain, and then doing a forward DNS look up using that googlebot name. This is useful if you're concerned that spammers or other troublemakers are accessing your site while claiming to be Googlebot. -Google
编辑以进一步解释 假设您使用的是 php,您会在运行时生成链接。这是我编写的一些代码。
function getRealURL($url)
{
// adjust this regex to match the pattern of your traffic analysis urls
ereg("link=(.+)$",$url,$matches);
if ($matches[1])
{
// adjust this so the urls come out correctly
return "http://www.".$matches[1].".com";
}
else
{
return $url;
}
}
function isGoogle()
{
switch ($_SERVER['HTTP_USER_AGENT'])
{
case 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)':
case 'Googlebot/2.1 (+http://www.googlebot.com/bot.html)':
case 'Googlebot/2.1 (+http://www.google.com/bot.html)':
return true;
default:
return false;
}
}
function showlink($url)
{
$trafficAnalysisUrl = getRealURL($url);
if (isGoogle())
{
return $url;
}
else
{
return $trafficAnalysisUrl;
}
}
<html>
...
Come eat pizza at <a href='<?=showLink("link.php?link=chuckecheese")?>'>chuck e cheese!</a>
...
</html>
我怀疑谷歌会关心这样的事情,因为两个链接都指向同一个地方。 但是请检查 TOS 以确保。 http://www.google.com/accounts/TOS
关于.htaccess - 帮助处理来 self 网站的传出链接的 301 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1146080/