大众301重定向使用的.htaccess [英] Mass 301 redirect using .htaccess

查看:189
本文介绍了大众301重定向使用的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,涉及以数千(30,000)静态网页,使之成为一个CMS一个大项目。

I am working on a large project that involves taking thousands (30,000+) static web pages and turning it into to a CMS.

问题是许多这些网页都是他们的目录中出现重复。我希望通过使用301重定向,以保持完整的搜索引擎优化,但是,我不知道如何去这样做这么大的重定向(301)。

The issue is many of these pages are duplicates within their directories. I want to keep the SEO intact by using 301 redirects, however, I am not sure how to go about doing such a large redirect (301).

下面是对页面具有当前目录结构的一个例子。

Here is an example of the current directory structure for the pages.


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

正如你所看到的 page.html即可的是重复的所有目录。

As you can see page.html is duplicated in all the directories.

有关新型农村合作医疗的URL,该网页将只是 /page.html

For the new CMS the URL to that page would just be /page.html.

推荐答案

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

Working example, visit: http://www.jakeisonline.com/stackoverflow/3345518-mass-301-redirect/page.html

You should be redirected straight to /page.html

Options +FollowSymlinks
RewriteEngine on

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

这将始终重定向<一个href="http://www.foo.com/something/something/something/page.html">http://www.foo.com/something/something/something/page.html回到 http://www.foo.com/page.html 使用301重定向硬

This will always redirect http://www.foo.com/something/something/something/page.html back to http://www.foo.com/page.html using a 301 hard redirect.

重写规则做到这一点通过查看URL,如果page.html即可之前任何包含(不含域本身)确定,如果是,则在301重定向。所以,你可以从字面上使用任何分层次,只要它与page.html即可结束,它会重定向在根目录下/page.html。

The rewrite rule does this by looking at the URL, determining if anything before page.html is included (excluding the domain itself) and if it is, will 301 redirect. So you can literally use any sub-level, and as long as it ends with page.html, it will redirect to /page.html in the root directory.

如果你想知道什么 [R = 301,NC] 表示,

In case you're wondering what [R=301,NC] means,

 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'

这篇关于大众301重定向使用的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆