Htaccess:重定向整个域,同时将某些用户代理重定向到其他域?

Htaccess: Redirecting entire domain while redirecting certain user agents to other domain?

如标题所述,我想将整个域重定向到单个 URL,同时将某些用户代理重定向到不同的域。 重要的是所有重定向都由 htaccess 启动。 到目前为止,这是我的代码:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.com
RewriteRule (.*) http://newdomain.com [R=301,L]

RewriteCond %{REQUEST_URI} !/robots.txt$
RewriteCond %{HTTP_USER_AGENT} ^.*YandexBot.*$ [NC]
RewriteCond %{HTTP_USER_AGENT} ^.*BaiduSpider.*$ [NC]
RewriteRule ^.*.* http://otherdomain.com [L]

如有任何帮助,我们将不胜感激!

编辑:我的代码现在如下所示:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^olddomain\.de [NC]
RewriteCond %{REQUEST_URI} !/robots\.txt$
RewriteCond %{HTTP_USER_AGENT} ^.*BLEXBot.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*BlackWidow.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Nutch.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Jetbot.*$ [NC,OR]
# [...] (a lot more user agents)
RewriteCond %{HTTP_USER_AGENT} ^.*gigabot.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*BlekkoBot.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*Nexus 10.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*YandexBot.*$ [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*BaiduSpider.*$ [NC]
RewriteRule ^ http://www.otherdomain.de/ [L]

RewriteCond %{HTTP_HOST} ^olddomain\.de [NC]
RewriteRule ^ https://newdomain.de/ [R=301,L]

当我使用上面的 htaccess 文件时,服务器仍然返回 500 内部服务器错误。 我的 robots.txt 应该是什么样子?目前还没有修改过。有必要吗?

您可以使用:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^olddomain\.com [NC]
RewriteCond %{REQUEST_URI} !/robots\.txt$
RewriteCond %{HTTP_USER_AGENT} YandexBot [NC,OR]
RewriteCond %{HTTP_USER_AGENT} BaiduSpider [NC]
RewriteRule ^ http://otherdomain.com [L]

RewriteCond %{HTTP_HOST} ^olddomain\.com [NC]
RewriteRule ^ http://newdomain.com [R=301,L]

在域之前使用机器人重定向。并且 OR 在每个新用户代理之后。
无需使用 ^.*.*$