Mass 301重定向使用.htaccess

时间:2010-07-27 15:59:21

标签: apache .htaccess redirect seo http-status-code-301

我正在开展一个大型项目,涉及获取数千(30,000+)个静态网页并将其转换为CMS。

问题是这些页面中的许多页面在其目录中都是重复的。我想通过使用301重定向保持SEO完好无损,但是,我不知道如何进行如此大的重定向(301)。

以下是页面当前目录结构的示例。

/page.html
/folder/page.html
/folder/subfolder/page.html
/folder/subfolder/anotherfolder/page.html

正如您所见, page.html 在所有目录中都是重复的。

对于新的CMS,该网页的网址只有/page.html

2 个答案:

答案 0 :(得分:6)

工作示例,访问:http://www.jakeisonline.com/stackoverflow/3345518-mass-301-redirect/page.html

您应该直接重定向到/page.html

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.*)page.html /page.html [R=301,NC]

这将始终使用301硬重定向将http://www.foo.com/something/something/something/page.html重定向回http://www.foo.com/page.html

重写规则通过查看URL,确定是否包含page.html之前的任何内容(不包括域本身)来执行此操作,如果是,则301将重定向。所以你可以逐字地使用任何子级别,只要它以page.html结尾,它就会重定向到根目录中的/page.html。

如果您想知道[R=301,NC]的含义,

 R // means simple redirect
 R=301 // means redirect with a 301 header
 NC // means no-case, or case insensitive
 L // can also be used to say 'ignore all the other rules after this'

答案 1 :(得分:0)

尝试此规则:

RewriteRule ^([^/]+/)+page\.html$ /page.html [L,R=301]

或任意 page.html

RewriteRule ^([^/]+/)+([^/]+)\.html$ /$2.html [L,R=301]
相关问题