0

我为爬虫和搜索引擎设置了 .htaccess 条件,它将它们带到一个“静态”页面,在那里它们可以抓取所有内容。

到目前为止,我的域{client} .realdomain.com 其中{client}是一个客户的子域。

当客户然后在社交网络上分享某些东西时,例如 facebook/linkedin,他们的爬虫被带到我的 .htaccess 中,它具有以下条件(并且这有效)

网址示例:http://{client}.realdomain.com/s/token

RewriteCond %{HTTP_USER_AGENT} (LinkedInBot/[0-9]|facebookexternalhit/[0-9]|Facebot|Twitterbot|twitterbot|Pinterest|pinterest|Google.*snippet|baiduspider|rogerbot|embedly|quora\ link\ preview|showyoubot|outbrain|slackbot|vkShare|W3C_Validator)
RewriteCond %{HTTP_HOST} ^(.+?)\.realdomain\.com$
RewriteRule ^s/(.*)$ http://%1.realdomain.com/static.php?token=$1 [NC,L]

最终将成为http://{client}.realdomain.com/static.php?token=token

如前所述,这里的任何东西都很完美,但现在我正在转向拥有不同的域,所以它可以

{client}.real-domain.com{client}.sunset.com

我在我的 .htaccess 中本质上是相同的东西,但是当它重定向时它应该带着整个域,所以它会去,例如http://{client}.sunset.com?static.php=token=my-secret-token,如果一个爬虫来{client}.sunset.com/s/my-secret-token

我该怎么做呢?我似乎是一个简单的解决方案,但由于某种原因,我似乎无法理解它。

谢谢

4

1 回答 1

1
RewriteCond %{HTTP_USER_AGENT} (LinkedInBot/[0-9]|facebookexternalhit/[0-9]|Facebot|Twitterbot|twitterbot|Pinterest|pinterest|Google.*snippet|baiduspider|rogerbot|embedly|quora\ link\ preview|showyoubot|outbrain|slackbot|vkShare|W3C_Validator)
RewriteCond %{HTTP_HOST} ^(.+?)\.%{HTTP_HOST}%\.com$
RewriteRule ^s/(.*)$ http://%1.%{HTTP_HOST}%.com/static.php?token=$1 [NC,L]

你能测试一下吗?通过将您的域名替换为%{HTTP_HOST}%

于 2018-03-06T13:27:20.277 回答