Mass 301重定向使用.htaccess

mic*_*ano 5 apache .htaccess seo redirect 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,该页面的URL就是/page.html.

jak*_*ine 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]
Run Code Online (Sandbox Code Playgroud)

这将始终使用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'
Run Code Online (Sandbox Code Playgroud)