帮助处理来自我网站的传出链接的 301 重定向

发布于 2024-07-29 00:41:06 字数 792 浏览 4 评论 0原文

我工作的公司通过跟踪合作伙伴的第三方网站链接到合作伙伴。 例如,在我们的网站上会有一个类似这样的传出链接(名称已更改以保护我的工作):

<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 的优秀人员在我继续工作中所扮演的角色。

I work for company that links out to partners through a third party website that tracks them. So for example on our site there will be an outgoing link something like this (names changed to protect my work):

<a href="link.php?link=chuckecheese">check it out kids!</a>

if you go into link.php, you see I define the link there:

$outlink['chuckecheese'] = "http://partners.linktrackingisprettycool.com/x/212/CD1/$STAMP";

$STAMP is a timestamp and is replaced with, say, "12-25-09-1200" for noon on christmas.

When a user clicks on this link, he goes to www.chuckecheese.com

This all works fine, but it isn't as good for SEO purposes as it could be. I want to make it so that search engines will see it as a link to chuckecheese.com, which which helps our partners' pageranks and is more honest.

I'm in .htaccess trying to make up rewrite rules but I'm confused and don't know exactly how it's done. I tried:

RewriteRule http://www.chuckecheese.com$ link.php?link=chuckecheese$ [QSA]

But this doesn't seem to work. What should I try next?

Thanks in advance for any help. You guys on here are always awesome and I appreciate the part that the good people at stack overflow play in me remaining employed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

江城子 2024-08-05 00:41:06

您不能为此使用重写规则来重定向用户。 该请求必须由您的网络服务器处理。

您可以尝试执行一些 javascript 来实现此目的。 所以href是chuckecheese,但是onclick,你将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 时,您将显示进行流量分析的链接。

您可以在以下网址找到用户代理列表:

如果 googlebot 没有显示正确的用户代理(或者将来会发生变化),google 建议您对 IP 地址进行反向查找。 这将对性能造成很小的影响。

您可以通过使用反向 DNS 查找来验证访问您服务器的机器人是否确实是 Googlebot,验证该名称是否位于 googlebot.com 域中,然后使用该 googlebot 名称进行正向 DNS 查找。 如果您担心垃圾邮件发送者或其他麻烦制造者在声称是 Googlebot 的情况下访问您的网站,这会很有用。 -Google

已编辑以获取进一步说明< /b>
假设您使用的是 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>

我怀疑谷歌会关心这样的事情,因为两个链接都指向同一个地方。
但请检查服务条款以确定。
http://www.google.com/accounts/TOS

You can't use a rewrite rule to redirect the user for this. The request has to be one processed by your webserver.

You might try doing some javascript to achieve this. so the href is to chuckecheese, but onclick, you change the document.location to what you really want to do.

Edited question for bounty

What you could do is pre-process your links based on the user agent of the browser. So when the user-agent is googlebot (one of the below strings), You display the real url of 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)

When the URL is not googlebot, you display the link that does traffic analytics.

You can find a list of user agents at the following URLs:

If googlebot isn't showing the correct user-agent (or it changes in the future) google recommends you do a reverse look up against the IP address. This will be a small performance hit.

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

Edited for further explanation
Assuming you are using php, you generate the link at runtime. Here is some code I whipped up.

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>

I doubt google would care about something like this since both links go to the same place.
But check the TOS to be sure.
http://www.google.com/accounts/TOS

讽刺将军 2024-08-05 00:41:06

你的假设并不好。 你说:

我想让它能够搜索
引擎会将其视为链接
chuckecheese.com,这有助于我们
当人们搜索chuck e时得分
奶酪,因为我们会被视为
直接链接到他们。

如果这真的有助于 SEO,那么每个人都会垃圾邮件链接所有优秀的网站,只是为了获得 SEO 页面排名,而游戏就太简单了。 链接的受益人是收件人页面/站点,而不是发件人。

An assumption of yours is not good. You say:

I want to make it so that search
engines will see it as a link to
chuckecheese.com, which helps our
score when people search for chuck e
cheese because we'll be seen as
linking right to them.

If this really helped SEO wise, every body would spam link all great sites just to get SEO pagerank and the game would just be too easy. The beneficiary of a link is the recipient page/site, not the sender.

耀眼的星火 2024-08-05 00:41:06

嘿,PG...链接到其他网站不会给您带来任何进一步的 PageRank,就像您在 AdWords 中的广告出现在一千个其他网站上不会给您带来 PageRank 一样。 是的,您的合作伙伴会因您与他们的联系而受益。 那么您所说的开放带来的好处又是什么呢? 根据我对你所写内容的理解,这只是另一个奇特的重定向。 谷歌知道这一点。

Hey PG... linking out to other websites will not give you any further PageRank just as having your ads in Adwords appearing on a thousand other sites will not give you PageRank. And yes, your partners are being benefited by having you linked to them. And what about those benefits to be gain that you speak of from being open? From my understanding of what you have wrote, it is just another fancy redirect. Google knows that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文