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'll show you how to easily change the default search URL slug in WordPress and make it more user-friendly and user-friendly.

how to edit the search url on WordPress.png

Why change the default search URL in WordPress

WordPress uses a user-friendly URL structure SEO for all pages of your Website. Typical WordPress URLs for search engines look like this:

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 for search engines.

However, WordPress still uses an unfriendly URL for the search results page. A typical search URL in WordPress looks like this:

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

This URL structure does not match the rest of the URLs in your Website. While some WordPress search plugins improve search results, most do nothing about the search URL itself.

And if you can make your search URL look like this:

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

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

Changing the URL of the Slug search page on WordPress

For this tutorial, you will need to modify the files of your WordPress theme.

Method 1. Edit WordPress search URL slug via functions file

This method is easier and recommended for most users.

First of all, you need to copy and paste the following code into your theme's functions.php file or into a plugin:

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

Do not forget to save your changes.

You can now access your Website and try to use the search functionality. You will notice that the search URL looks like this:

http://example.com/search/votre-recherche/

Method 2. Modify Slug Search URL via htaccess file

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

Your .htaccess file is located in the root folder of your website and you will need to use the FTP application or the File Manager in the cPanel to edit it.

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

# Change WordPress search URL RewriteCond% {QUERY_STRING} \? S = ([^ &] +) [NC] RewriteRule ^ $ / search /% 1 /? [NC, R, L]
Remember to save your changes and upload the .htaccess file to the server.

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

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

We hope this article has helped you change the default search URL slug in WordPress.