slug怎么放到url中_如何在WordPress中更改默认搜索URL Slug
发布日期:2021-09-25 18:43:39 浏览次数:2 分类:技术文章

本文共 4330 字,大约阅读时间需要 14 分钟。

slug怎么放到url中

Do you want to change the default search URL slug in WordPress? By default, WordPress search URLs are not user friendly. In this article, we will show you how to easily change the default search url slug in WordPress and make it more SEO and user friendly.

您是否要更改WordPress中的默认搜索URL段? 默认情况下,WordPress搜索URL对用户不友好。 在本文中,我们将向您展示如何轻松地在WordPress中更改默认搜索URL插件,并使它更加SEO和用户友好。

Changing default WordPress search URL slug

为什么要在WordPress中更改默认搜索URL Slug (Why Change Default Search URL Slug in WordPress)

WordPress uses for all pages on your website. Typical SEO friendly WordPress URLs look like this:

WordPress对您网站上的所有页面均使用 。 典型的SEO友好WordPress URL如下所示:

http://example.com/some-page/

http://example.com/2018/03/some-article/
http://example.com/category/some-category/

http://example.com/some-page/

http://example.com/2018/03/some-article/
http://example.com/category/some-category/

As you can see, these URLs are quite easy to understand for users as well as search engines.

如您所见,这些URL对于用户和搜索引擎而言都很容易理解。

However, WordPress still uses non-friendly URL for search results page. A typical search URL in WordPress looks like this:

但是,WordPress仍将非友好URL用于搜索结果页面。 WordPress中的典型搜索URL如下所示:

http://example.com/?s=search-term

http://example.com/?s=search-term

This URL structure doesn’t match the rest of your website URLs. While some improve the search results, most don’t do anything about the search URL itself.

此网址结构与您网站的其余网址不匹配。 尽管某些改善搜索结果,但大多数都不会对搜索URL本身做任何事情。

What if you can make your search URL look like:

如果您可以使搜索网址看起来像:

http://example.com/search/your-search-term/

http://example.com/search/your-search-term/

Let’s take a look at how to make the WordPress search page URL slug more SEO friendly.

让我们看一下如何使WordPress搜索页面URL标记更加SEO友好。

影片教学 (Video Tutorial)

If you don’t like the video or need more instructions, then continue reading.

如果您不喜欢该视频或需要更多说明,请继续阅读。

在WordPress中更改搜索页面URL标记 (Changing Search Page URL Slug in WordPress)

For this tutorial you will need to edit your WordPress theme files. If you haven’t done this before, then please take a look at our guide on in WordPress.

对于本教程,您将需要编辑WordPress主题文件。 如果您以前没有做过,请查看我们的指南, 在WordPress中 。

方法1.通过功能文件更改WordPress搜索URL Slug (Method 1. Change WordPress Search URL Slug via Functions File)

This method is easier and recommended for most users.

此方法更简单,建议大多数用户使用。

First, you need to copy and paste the following code in your theme’s file or a :

首先,您需要将以下代码复制并粘贴到主题的文件或于 :

function wpb_change_search_url() {	if ( is_search() && ! empty( $_GET['s'] ) ) {		wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );		exit();	}	}add_action( 'template_redirect', 'wpb_change_search_url' );

Don’t forget to save your changes.

不要忘记保存您的更改。

You can now go to your website and try using the search feature. You will notice that the search URL looks like this:

现在,您可以转到您的网站并尝试使用搜索功能。 您会注意到搜索URL如下所示:

http://example.com/search/your-search-query/

http://example.com/search/your-search-query/

方法2。通过htaccess文件更改搜索URL Slug (Method 2. Change Search URL Slug via htaccess File)

The is often used to set up redirects and other website configuration tasks. You can also use it to change the default search URL slug in WordPress.

通常用于设置重定向和其他网站配置任务。 您也可以使用它来更改WordPress中的默认搜索URL段。

Your .htaccess file is located in your website’s root folder, and you will need to use FTP or File Manager app in cPanel to edit it. Refer to this guide, if you .

您的.htaccess文件位于网站的根文件夹中,您将需要使用cPanel中的FTP或文件管理器应用程序对其进行编辑。 如果 ,请参考本指南。

In your .htaccess file, you need to paste the following code at the bottom:

在您的.htaccess文件中,您需要在底部粘贴以下代码:

# Change WordPress search URLRewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC]RewriteRule ^$ /search/%1/? [NC,R,L]

Don’t forget to save your changes and upload the .htaccess file back to the server.

不要忘记保存更改并将.htaccess文件上传回服务器。

You can now go to your website and use the search feature. You will notice the search URL will now look like this:

现在,您可以转到您的网站并使用搜索功能。 您会发现搜索URL现在将如下所示:

http://example.com/search/your-search-query/

http://example.com/search/your-search-query/

We hope this article helped you change the default search URL slug in WordPress. You may also want to see our list of .

我们希望本文能帮助您更改WordPress中的默认搜索URL段。 您可能还希望查看我们的 。

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

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

翻译自:

slug怎么放到url中

转载地址:https://blog.csdn.net/cumyupx7788305/article/details/108613292 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:wordpress会员插件_5个最佳WordPress会员插件(比较)– 2020年
下一篇:如何使用更多字段插件在WordPress中创建自定义写面板

发表评论

最新留言

做的很好,不错不错
[***.243.131.199]2024年03月23日 09时28分09秒