如何正确进行301重定向 [英] How to properly make 301 redirect

查看:90
本文介绍了如何正确进行301重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有50多个html页面,这些页面将移至同一域中的不同文件夹.

I have over 50 html pages that I'm going to move to different folders in the same domain.

如何正确地为每个重定向进行301次重定向?

How to properly make 301 redirects for each one?

有人说将重定向放置在 meta html标签中.像这样< meta http-equiv ="refresh" content ="0; url = http://example.com/"/>

Some people said to place the redirect in meta html tags. Like this <meta http-equiv="refresh" content="0; url=http://example.com/" />

其他人说要在.htaccess文件中添加它,我不确定什么是最好的方法?

Some other people are saying to make it inside the .htaccess file, I'm not sure what's the best way?

我的目标是将旧的URL重定向到这些URL,而不会丢失Google中的页面排名.

My goal is to redirect the old URLs to the URLs without losing the page rank in Google.

推荐答案

在大多数情况下,301重定向是在网站上实现重定向的最佳方法.使用元刷新不会会让阅读实体(Google,浏览器或其他)知道它是永久性的,因此会对SEO产生负面影响.

In most instances, a 301 redirect is the best way to implement redirects on a website. Using a meta refresh won't let the reading entity (Google, a browser or otherwise) know that it's permanent and thus would have a negative impact in terms of SEO.

301重定向本质上是指已永久移动"作为HTTP状态代码,并且会出于SEO的目的而被识别.

A 301 redirect essentially means "Moved Permanently" as an HTTP status code and will be recognised for SEO purposes.

在.htaccess文件中实现此操作是最有效的方法,因为它全部在一个地方完成,并且不需要对所有单个文件进行可能的编辑(在您的情况下为50个).

Achieving this within an .htaccess file is the most efficient way of doing this as it's all done in one place and won't require the potential editing of all the individual files (50 in your case).

将其作为.htaccess文件中的简单列表进行操作:

Do this as a simple list inside an .htaccess file:

RewriteEngine on
Redirect 301 /oldfolder/file1.html /newfolder/file1.html
Redirect 301 /oldfolder/file2.html /newfolder/file2.html

或者,如果所有文件都位于一个文件夹中,则可以使用类似于下面的ReWriteRule,它可以更快地测试和实现:

Or, if all the files reside in one folder, you could use a ReWriteRule similar to below that's a lot quicker to test and implement:

RewriteEngine on
RewriteRule ^oldfolder/(.*)$ /newfolder/$1 [R=301,NC,L]

供参考:
R = 301告诉搜索引擎重定向是永久的
NC告知引擎不要在意规则中的字符
L告诉Apache这是最后一条规则,将避免解析/循环等

For reference:
R=301 tells search engines that the redirection is permanent
NC tells the engine not to care about the characters in the rule
L tells Apache it's the last rule and will avoid parsing/loops etc

这篇关于如何正确进行301重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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