.htaccess: rewriteCond 到同一个 URL 内的另一个页面与参数

.htaccess: rewriteCond to another page within same URL with params

我的 .htaccess 有一个适用于爬虫和搜索引擎的条件,它将它们带到一个 "static" 页面,在那里它们可以抓取所有内容。

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

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

URL 示例: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= [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

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

谢谢

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= [NC,L]

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