Excellent software and practical tutorials
Why You Should Change the Default Search URL Slug in WordPress
Do you want to change the default search URL slug in WordPress? By default, the WordPress search URL is not user-friendly nor optimized for SEO. In this article, we will show you how to easily change the default search URL slug in WordPress to make it more SEO and user-friendly.
By default, WordPress uses an SEO-friendly URL structure for all pages on your site. A typical SEO-friendly WordPress URL might look like this:
- http://example.com/some-post/
- http://example.com/2018/03/news-article/
- http://example.com/category/some-category/
As you can see, these URLs are easy for visitors to understand, which will help them find their way around your website. They also tell search engines useful information about the page, which can help them rank your content correctly and display it in relevant search results.
However, a typical search URL in WordPress looks like this:
http://example.com/?s=search-term
The extra ?s= characters make the URL harder to read and understand, which can confuse search engines and your visitors.
While some WordPress search plugins can help you display more accurate and detailed search results, most plugins don’t change the search URL itself.
That being said, let’s look at how to change the search URL slug and improve your WordPress SEO. Simply use the links below to jump directly to the method you want to use.
- Method 1. Change WordPress search URL slug using WPCode
- Method 2. Change the search URL slug via htaccess file
Method 1. Change WordPress Search URL Slug Using WPCode
The easiest way to change the default WordPress search slug is to useWPCode.
WPCode is the most popular code snippet plugin used by over 1 million WordPress sites. It allows you to add code snippets in WordPress without editing your site's functions.php file.
First thing you need to do is install and activate the free WPCode plugin on your website. For more details, see our step by step guide on how to install a WordPress plugin.
After activation, go to Code Snippets » Add Snippet.

This will take you to the Add Snippet page where you can see WPCode’s library of ready-made snippets.
Since we’re going to add our own snippet, hover over “Add your custom code (new snippet).” Then, click “Use snippet” when it appears.

You need to first enter a title for your custom snippet.
This can be anything that helps you identify the snippet in the WordPress admin area.

Since we are adding a PHP snippet, open the Code Type drop-down menu and select PHP Snippet.
You can then go ahead and paste the following code into the code box:
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' );
This code snippet replaces the "/?s=search-term" characters with "search", so your slug will look like: http://example.com/search/wordpress
To use something other than "search" in your URLs, simply customize the code snippet above.
When you’re happy with your code, it’s time to change where the snippet runs by scrolling to the “Insert” box.
First, make sure "Automatically insert" is selected. Then, open the "Location" drop-down menu and select "Front End Only," since we'll only be using this code on the public-facing front end of our site.

You can also assign tags to your code snippets. This will help you sort your code snippets by topic and functionality.
If you’re happy with how your snippet is set up, scroll to the top of the screen and click “Save Snippet.”

After that, you can make the code snippet live on your website by clicking the Active switch.
Don’t forget to save this change by clicking Update.

Now, visit your site and perform a search.
If you look in your browser's address bar, you'll see the new SEO-friendly search URL.

Method 2. Change WordPress Search URL Slug via htaccess File
Another option is to edit the .htaccess file. This method is more complicated, so it is not recommended for beginners.
To access the .htaccess file, you will need an FTP client such as FileZilla, or you can use the File Manager of your WordPress hosting cPanel. If this is your first time using FTP, then you can check out our complete guide on how to connect to your site using FTP.
Once you're done, open .htaccess and paste the following code at the bottom of the file:
# Change WordPress search URL RewriteCond %{QUERY_STRING} \\?s=([^&]+) [NC] RewriteRule ^$ /search/%1/? [NC,R,L]
This will change the WordPress search slug to the following:
http://example.com/search/your-search-query/
You can change this slug by customizing the snippet.
Once you are finished, don’t forget to save your changes and upload the .htaccess file back to your server.
Now if you perform a search on your site, you’ll notice that it’s using the new slug.