wordpress零基础到_如何在WordPress中更改类别基础前缀

wordpress零基础到

Do you want to change the category base prefix in WordPress? By default, WordPress automatically adds /category/ as a prefix to URLs for all category pages. In this article, we will show you how to change the category base prefix in WordPress. We will also talk about whether or not you should remove the base prefix altogether.

您是否要在WordPress中更改类别基础前缀? 默认情况下,WordPress自动为所有类别页面的URL添加/ category /作为前缀。 在本文中,我们将向您展示如何在WordPress中更改类别基本前缀。 我们还将讨论是否应完全删除基本前缀。

How to change the category base prefix in WordPress
什么是类别基本前缀? 你应该改变它吗? (What is Category Base Prefix? Should You Change It?)

Each category on your WordPress site get its own page and RSS feed. You can view all posts filed under a category by visiting that category archive page.

WordPress网站上的每个类别都有其自己的页面和RSS feed 。 您可以通过访问该类别存档页面来查看归入该类别的所有帖子。

By default, WordPress adds ‘category’ as base prefix to URLs for category pages. This helps differentiate pages and posts from category and tag archives.

默认情况下,WordPress将“类别”作为基本前缀添加到类别页面的URL。 这有助于区分页面和帖子与类别和标签存档。

For example, if you have a category called ‘News’ then its URL will look like this:

例如,如果您有一个名为“新闻”的类别,则其URL将如下所示:

http://example.com/category/news/

http://example.com/category/news/

Similarly, WordPress also adds tag prefix to URLs for tag archives.

同样,WordPress还为标签档案库的 URL添加标签前缀。

http://example.com/tag/iphone/

http://example.com/tag/iphone/

This SEO friendly URL structure helps users and search engines understand what kind of page they are visiting.

这种SEO友好的URL结构可帮助用户和搜索引擎了解他们正在访问哪种页面。

Most websites don’t need to change the base prefix at all. However, if you are creating a niche site where you would like to use a different word or phrase for your categories, then you can change the category base prefix to reflect that.

大多数网站根本不需要更改基本前缀。 但是,如果您要创建一个利基网站,而您想为类别使用其他单词或短语,则可以更改类别基础前缀以反映这一点。

在WordPress中更改类别基本前缀 (Changing Category Base Prefix in WordPress)

Changing category base prefix is quite simple in WordPress.

在WordPress中,更改类别基本前缀非常简单。

You need to visit Settings » Permalinks page and scroll down to the ‘Optional’ section.

您需要访问设置»永久链接页面,然后向下滚动到“可选”部分。

Changing category base prefix in permalink settings

Here you can enter the prefix you would like to use next to the category base option. You can also change the tag base prefix if you want.

在这里,您可以在类别基本选项旁边输入要使用的前缀。 您也可以根据需要更改标签的基本前缀。

Don’t forget to click on the save changes button to store your settings.

不要忘记单击“保存更改”按钮来存储您的设置。

更改类别基本前缀后设置重定向 (Setting up Redirects After Changing Category Base Prefix)

If you are changing category base prefix on a new website, then you don’t need to do anything. However, if you are doing this on an existing website, then users visiting the old category page will see a 404 error.

如果要在新网站上更改类别基本前缀,则无需执行任何操作。 但是,如果您在现有网站上执行此操作,则访问旧类别页面的用户将看到404错误

To fix this, you will need to setup redirect to make sure both search engines and regular visitors are properly redirected to the correct category page on your site.

要解决此问题,您将需要设置重定向,以确保将搜索引擎和常规访问者都正确地重定向到您网站上的正确类别页面。

First you will need to install and activate the Redirection plugin. For more details, see our step by step guide on how to install a WordPress plugin.

首先,您需要安装并激活重定向插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

Upon activation, you need to visit Tools » Redirection page to setup redirect.

激活后,您需要访问工具»重定向页面以设置重定向。

Setting up redirect after changing category prefix

Scroll down to ‘Add new redirection’ section.

向下滚动到“添加新重定向”部分。

First, you need to add /category/(.*) in the source URL field. After that you need to check the box next to the regular expression option.

首先,您需要在源URL字段中添加/category/(.*) 。 之后,您需要选中正则表达式选项旁边的框。

In the target URL field, you need to add your new category base prefix like this /topics/$1. Don’t forget to replace topics with your new category prefix.

在目标URL字段中,您需要添加新的类别基础前缀,例如/topics/$1 。 不要忘记用新的类别前缀替换主题。

Click on the ‘Add Redirection’ button to save your changes.

点击“添加重定向”按钮以保存您的更改。

That’s all. Now all your users and search engines will be redirected to the correct URLs using your new category prefix.

就这样。 现在,您的所有用户和搜索引擎将使用新的类别前缀重定向到正确的URL。

在WordPress中删除类别基本前缀 (Removing The Category Base Prefix in WordPress)

Many of our users have asked us about removing the category base prefix from WordPress URLs altogether. This will change your category URLs to look like this:

我们的许多用户都问过我们是否要从WordPress URL中完全删除类别基本前缀。 这将更改您的类别URL,如下所示:

http://example.com/news/

http://example.com/news/

This is not a good idea, and we recommend that you do not remove category base prefix.

这不是一个好主意,我们建议您不要删除类别基本前缀。

Category base prefix helps both users and search engines distinguish between posts/pages and categories. Removing the prefix makes your URLs ambiguous which is not good for user experience or SEO.

类别基本前缀可帮助用户和搜索引擎区分帖子/页面和类别。 删除前缀会使您的URL模棱两可,这不利于用户体验或SEO。

You may also run into technical issues with various WordPress plugins. For example, if you have a category and a page with the same name or when you are using %postname% as your URL structure for single posts, then your site will experience infinite redirect loop causing the pages to never load.

您可能还会遇到各种WordPress插件的技术问题。 例如,如果您有一个类别和一个具有相同名称的页面,或者当您使用%postname%作为单个帖子的URL结构时,则您的站点将遇到无限重定向循环,从而导致页面永远不会加载。

However, if you still want to do this, then you need to install and activate FV Top Level Categories plugin. For more details, see our step by step guide on how to install a WordPress plugin.

但是,如果仍然要执行此操作,则需要安装并激活FV顶级类别插件。 有关更多详细信息,请参阅有关如何安装WordPress插件的分步指南。

The plugin works out of the box and will immediately remove the category base prefix from your category URLs.

该插件开箱即用,将立即从类别URL中删除类别基础前缀。

We hope this article helped you learn how to change the category base prefix in WordPress. You may also want to see our list of most wanted WordPress tips, tricks, and hacks.

我们希望本文能帮助您学习如何在WordPress中更改类别基础前缀。 您可能还想查看我们最想要的WordPress技巧,窍门和hack列表

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

如果您喜欢这篇文章,请订阅我们的YouTube频道 WordPress视频教程。 您也可以在TwitterFacebook上找到我们。

翻译自: https://www.wpbeginner.com/wp-tutorials/how-to-change-the-category-base-prefix-in-wordpress/

wordpress零基础到

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值