Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 使用.htaccess进行Mass 301重定向_Apache_.htaccess_Redirect_Seo_Http Status Code 301 - Fatal编程技术网

Apache 使用.htaccess进行Mass 301重定向

Apache 使用.htaccess进行Mass 301重定向,apache,.htaccess,redirect,seo,http-status-code-301,Apache,.htaccess,Redirect,Seo,Http Status Code 301,我正在从事一个大型项目,涉及数千(30000+)个静态网页,并将其转换为CMS 问题是这些页面中有许多在其目录中重复。我想通过使用301重定向来保持SEO的完整性,但是,我不知道如何进行如此大的重定向(301) 下面是页面当前目录结构的示例 /page.html /folder/page.html /folder/subfolder/page.html /folder/subfolder/anotherfolder/page.html /page.html /folder/page.html /

我正在从事一个大型项目,涉及数千(30000+)个静态网页,并将其转换为CMS

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

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

/page.html /folder/page.html /folder/subfolder/page.html /folder/subfolder/anotherfolder/page.html /page.html /folder/page.html /文件夹/子文件夹/page.html /folder/subfolder/anotherfolder/page.html 如您所见,page.html在所有目录中都是重复的

对于新的CMS,该页面的URL仅为
/page.html

工作示例,请访问: 您应该直接重定向到/page.html

Options +FollowSymlinks
RewriteEngine on

RewriteRule ^(.*)page.html /page.html [R=301,NC]
这将始终重定向回使用301硬重定向

重写规则通过查看URL,确定是否包含page.html之前的任何内容(不包括域本身),如果包含,则会重定向。因此,您可以直接使用任何子级别,只要它以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'
试试这个规则:

RewriteRule ^([^/]+/)+page\.html$ /page.html [L,R=301]
或者对于任意的page.html:


这是一篇关于重定向的优秀文章,给出了来自多个web服务器或方法的示例
RewriteRule ^([^/]+/)+([^/]+)\.html$ /$2.html [L,R=301]