Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Change the Default Search URL Slug in WordPress

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.

Changing default WordPress search URL slug

Why Change Default Search URL Slug in WordPress

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

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

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

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

What if you can make your search URL look like:

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

Video Tutorial

Subscribe to WPBeginner

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

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 how to copy and paste code in WordPress.

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 functions.php file or a site-specific plugin:

function wpb_change_search_url() {
	if ( is_search() && ! empty( $_GET['s'] ) ) {
		wp_redirect( home_url( "/search/" ) . urlencode( get_query_var( 's' ) ) );
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:

Method 2. Change Search URL Slug via htaccess File

The .htaccess file 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.

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 can’t find the .htaccess file.

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

# Change WordPress search URL
RewriteCond %{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.

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

We hope this article helped you change the default search URL slug in WordPress. You may also want to see our list of 55+ most wanted WordPress tips, tricks, and hacks.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

15 CommentsLeave a Reply

  1. Thank you Respected Sir/Madam,

    I am looking for such code because I want to use theme default theme’s search box using “Google Custom Search Engine” for extra revenue. Finally I have done using this code (all credit goes to you Sir / Madam). I have basis knowledge about html ( I don’t learn @ any institution, I learned online….. Let’s go),
    Very Very Thanks again…..

    • You would use the first method and replace the word search with the word you wanted


  2. Works great. Any idea why this might leave off closing / as in instead of /search-term/

    • For the first method, depending on your permalinks it may not automatically add a trailing slash, if you wanted one you would need to add the trailing slash to the wp_redirect function or modify your permalink settings.


  3. Method 1 doesn’t work if I change “/search/” for another term. I triead “/busca/” that means search in portuguese…

    • Carlos is right. Same goes for method 2 (htacess method. The only word it will work for is “search”. If you try any other word like “result”, “busca”, “whatever”, etc, then you get a 404.

      Very confusing as to why it only works for the word “search”.

      • You may want to ensure you cleared your caching if you’ve edited the code from the article for a word other than search for one possible reason.


    • These methods alone won’t work, they only make the «pretty» slug, but the keyword you need to change is the WP rewrite rule for the query.

      You can use this code in your theme’s functions.hp to use any word you want (also includes the rule for the ‘page’ slug):

      function re_rewrite_rules() {
      global $wp_rewrite;
      $wp_rewrite->search_base = ‘buscar’;
      $wp_rewrite->pagination_base = ‘pagina’;
      add_action(‘init’, ‘re_rewrite_rules’);

  4. Do you meant that the search result page can be indexed by search engine?
    However, the content in the search result page is a kind of duplicate content as what we can find in the archieve, category or tag pages.

    PS. I am not an expert in SEO and might have wrong concept.

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.