将机器人重定向到静态版本的站点

时间:2015-07-30 11:00:20

标签: .htaccess mod-rewrite redirect seo

基本上,我想使用.htaccess文件将机器人从常规站点重定向到静态版本。

以下是这种情况: 我网站中的网址采用以下格式:

http://example.com/?p=something
http://example.com/index.html?p=something
http://example.com/basic.php?p=something

我希望使用.htaccess文件重定向机器人,通过将index.html替换为basic.php或将其添加(如果不存在),将前2个网址中的一个抓取到第3个网址之一。根也应该变成basic.php而不是index.html。

这是我当前的.htaccess文件,这是错误的,因为它仅在URL包含index.html时有效

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (googlebot|InfoSeek|msnbot|bingbot|Slurp|DuckDuckBot) [NC]
RewriteRule ^index\.html$ /basic.php [L,R]

如果某种善良的灵魂可以帮助我解决这个问题,我将不胜感激。感谢

1 个答案:

答案 0 :(得分:0)

http://example.com/?p=something
http://example.com/index.html?p=something

要匹配这两者中的任何一个,您只需要使模式(即URL路径)可选:

RewriteRule ^(index\.html)?$ /basic.php [L,R]

旁白:从SEO的角度来看,这有点可疑。它可以被视为"隐藏" - 向搜索引擎提供与用户不同的内容,这可能会产生负面影响。而且搜索引擎显然希望将您的静态网站(被重定向到的网页)编入索引,而不是用户"用户"见。