WordPress websites非常适合扩展业务。它们具有灵活性,可自定义,无编码(如果您愿意的话),并且可以为您想要完成的任何操作安装插件。

As your site scales, redirects become an inevitability. You’ll eventually need to start implementing them to ensure that visitors and search engines are routed to the pages they’re looking for and away from an error page. It’s best to learn how they work now than scramble tofix a broken link在路上。

Fortunately, creating redirects in WordPress is straightforward as long as you know what you’re doing. In this guide, you’ll learn what redirects are, how they support a good user experience and SEO strategy, when and why you’ll need to add them, and two methods to create redirects in WordPress.

Grow Your Business With HubSpot's Tools for WordPress Websites

There are several types of redirects, but, unless you’re a web developer, you only really need to know about two: 301 (permanent) redirects and 302 (temporary) redirects.

A 301 redirect is the one you’ll probably be using most. This redirect is permanent, meaning that a web page has been moved to a new location and you don’t plan to move it back to the original location. 301 redirects are also the best option to preserve search engine authority, which we’ll discuss later on.

A 302 redirect indicates that the new URL is temporary, and that youplan to move the web page back to its original location at some point. A 302 redirect may be used for updating or repairing web pages — for example, sending users to an alternative page while you fix a broken page — but it’s far less common than a 301 redirect.

由于您通常会处理301个重定向作为WordPress管理员,因此我们将在这篇文章中讨论。WordPress中的301重定向易于使用插件或一些代码设置。但是首先,重要的是要知道何时使用它们以及为什么需要使用它们。

何时在WordPress中使用重定向

Generally, you should use a 301 redirect whenever you’re moving a web page on your site from one URL to another URL and want to send any web traffic from the old URL to the new URL. If you don’t set up a redirect, users will receive a 404 (not found) error when visiting the old URL.

以下是一些要求永久重定向的情况:

  • 更换过时的页面:If you’ve added a new page to your website that serves more up-to-date content than another page, you can redirect the old page URL to the new one.
  • Removing a page from your site:If you plan to remove a page from your site, remember that URLs don’t just go away — search engines and some visitors will have saved the link to this removed page. To prevent a 404, redirect the URL of the removed page to a similar page, the home page, or a page that tells users the product or content is no longer available.
  • Changing your website structure:重新组织网站的结构涉及四处移动页面,这可能需要一个或多个重定向,以确保将访问者发送到正确的页面。
  • 更改永久链接:You may want to change your permalink structure so your URLs看起来更专业, are easier to read, and帮助您的SEO。In this case, redirect your old URLs to your new, updated URLs to prevent broken links.
  • 更改域名:If you get a new domain name, this will be reflected in your URL. Old URLs should be redirected to URLs containing your new domain name.
  • 将多个域路由到一个页面:To capture wayward traffic, website owners may purchase domain names that are similar to their primary domain name. This way, if a visitor types in the wrong domain, they’ll be redirected to the right website. This also keeps competitors from buying up similar domains and stealing traffic.
  • Saving an email campaign:Say you’ve sent out an email blast that contains a broken link … oops. While you can’t change the link in the email, you can redirect the broken URL to the correct URL. Crisis averted.

Why You Should Use Redirects in WordPress

为什么还要努力进行工作以建立重定向而不是什么都不做呢?有两个原因:用户体验和SEO。

User Experience

实施重定向的最明显原因是防止与您网站的断开链接。这些导致404个错误,导致用户体验差。您可能已经发生了这种情况 - 单击反向链接或旧书签,然后被带到错误页面。烦人,对吧?301重定向阻止这种情况发生。

If visitors do happen to find a broken URL, you can improve things a bit by creating a定制404页这会招待(甚至可以转换)访客,如这样:

a 404 page for a marketing agency website

图像源

This should only be a last resort as it’s still a poor user experience. Ideally, visitors should never have to reach this page. Why bother searching your site for the content they want when they could just as easily head to a competitor’s?

通过重定向,您可以确定,即使您移动,删除或更改了页面,用户也总是会转到正确的位置。

SEO

The more insidious consequences of 404s are their effects on yourWordPress SEO。毕竟,不仅仅是人类accessin游客g your website. Search engine crawlers are regularly pinging your website to index your content and site structure.

If one of these bots finds a 404, it will dock points from your site’s authority — search engines don’t want to recommend websites that appear broken or missing important resources. And, again, a clever 404 page won’t save you here.

通过适当地实现一个301重定向,搜索gines will know that your page was permanently moved or removed, and you’ll send bots to the correct page to avoid the broken link. As a result, your new URL will be properly indexed by these bots.

Additionally, another key benefit of permanent redirects is that they preserve the search ranking of the old URL. For instance, if you own a landing page with high authority and change its URL, the new URL will retain the authority of the old URL. The ranking of your landing page should not be affected significantly if at all.

Now that we know when and why to use redirects in WordPress, let’s learn how: First, we’ll discuss the plugin method, then an alternative manual method.

How to Redirect a URL in WordPress With a Plugin

A plugin is the simplest way to implement and monitor your WordPress website redirects, especially if you refrain from modifying WordPress files yourself.

有许多WordPress redirect plugins所有这些都类似地工作,使您可以创建基本的301重定向以及更复杂的站点重定向。有些还跟踪重定向,告诉您每个命中次数有多少次,并提醒您任何问题。

Here, we’ll be covering how to set up 301 redirects with two popular plugins, Redirection and All in One SEO.

重定向

重定向是最受欢迎的重定向插件之一,下载量超过200万。该插件易于使用,可靠,维护良好且完全免费。创建一个重定向301重定向:

1。Install and activatethe Redirection plugin.

2。In your dashboard, select工具>重定向

3。On the welcome screen, clickStart Setup

welcome page for the wordpress redirect plugin redirection

4。On the next screen, you can choose to allow Redirection to create automatic redirects when you change permalinks. You can also choose whether you’d like the plugin to log 404 errors and redirects on your site. Choose your preferences, then click继续设置

WordPress重定向插件重定向的设置页面

5。Next, Redirection will test its connection with theWordPress REST API。Once this test is successful, you can clickFinish Setup, 然后Finished!

6。You’ll be brought to the main Redirection page (工具>重定向) in your dashboard. Here, you can view all current redirects, as well as a log of redirect activity and 404 errors.

main redirects page for the wordpress redirect plugin redirection

7.要添加新的重定向,请首先粘贴您要重定向的URLSource URL字段。

8.将您要重定向到的URL粘贴到Target URL字段。

creating a redirect with the redirection plugin

9.By default, this will create a 301 redirect. To create a different redirect or to toggle advanced settings, click the cog icon. You can give your redirection a title, matching criteria for the redirect, and/or an action when a match is found.

10.When finished, clickAdd Redirect。You’ll see your new redirect added to the list. To test your redirect, click检查重定向并看到您已连接到目标URL。If you have logging turned on, you’ll see this activity by clickingLogabove.

a completed redirect in the redirection plugin

All in one SEO

All in One SEO(AIOSEO) is another popular, powerful plugin to help you improve your search ranking. The Pro and Elite versions of the AIOSEO include a redirection manager that finds broken links and sets 301 redirects for them. You can also create redirects yourself through the plugin.

To create a 301 redirect with AIOSEO:

1。Install, activate, and set up the AIOSEO plugin.

2。In your dashboard, select全部seo>重定向。您将被带到重定向tab.

main redirect page in the wordpress redirect plugin all in one seo

图像源

3。Paste the URL you want to redirect from into theSource URL字段。离开你的域名和之前的一切e it out of the URL. For example, if your source URL is “https://www.example.com/old-page/”, only paste “/old-page/”. Into the field

4。将您要重定向到的URL粘贴到Target URL字段。该URL可以是相对URL或绝对(即完整)URL。

5。In theRedirect Type下拉,选择301 Moved Permanently

6。点击Add Redirect

7.您会看到您的新重定向添加到重定向列表中。在这里,您可以停用重定向。要测试您的重定向,请单击检查重定向并看到您已连接到目标URL。

redirection list in the wordpress redirect plugin all in one seo

图像源

How to Manually Redirect a URL in WordPress

If you’re comfortable editing server files directly, it’s also possible to set up redirects manually.

For this method, we’ll be modifying。htaccess,在大多数WordPress网站上找到的配置文件。编辑此文件时要谨慎,因为即使是小型错别字也可能会破坏您的网站。我们推荐making a backup of your current sitebefore going forward, just in case something goes wrong.

另外,请确保您可以直接修改服务器文件 - 检查托管提供商的文档或联系支持,以了解如何处理重定向。

To create a permanent redirect in .htaccess:

1。Go to your server filesystem. There are multiple ways to do this:

  • 通过您的托管帐户的控制面板,例如CPANEL
  • through anFTP客户端
  • 通过WordPress文件编辑器

2。找到您的.htaccess文件,该文件默认情况下位于网站的根目录中。如果您看不到它,请找到显示隐藏文件并将其打开的选项。

3。Open .htaccess in a text editor (depending on what tool you’re using, you may need to download the file to your computer).

4。要永久重定向一个页面,请在.htaccess文件的末尾粘贴以下代码:


# 301 redirect - single page
Redirect 301 /old-page

https://www.example.com/new-page/

… 在哪里/旧页是原始页面的相对URL,https://www.example.com/new-page/is the absolute URL of the target page.

5。To permanently redirect an entire site to another domain, paste the following code at the end of your .htaccess file:


#301重定向 - 网站范围内

Redirect 301 / https://example.com/

… 在哪里https://example.com/is the new website’s URL.

6。保存文件,并在必要时将文件重新上传到服务器。

7.通过访问旧URL并检查您发送到新URL的检查来测试重定向。

Send your users to the right place.

重定向are one of those tools that all website owners should know how to use. At some point, you’ll come across an instance when you’ll need to scrap one URL for another. However, URLs don’t just disappear, which is why redirects are so important for keeping your WordPress website healthy.

You’ve already done a lot to build authority in your space — don’t let broken links undo all of that work. Redirects are quick and simple, and they preserve your standing with visitors and search engines alike.

Use HubSpot tools on your WordPress website and connect the two platforms  without dealing with code. Click here to learn more.

Use HubSpot tools on your WordPress website and connect the two platforms  without dealing with code. Click here to learn more.

Originally published Nov 8, 2021 7:00:00 AM, updated November 08 2021

话题:

WordPress网站