Wordpress: Custom search result page throws 404

admin

Administrator
Staff member
I have followed the link <a href="https://codex.wordpress.org/Creating_a_Search_Page" rel="nofollow noreferrer">here</a> in codex and created the following
This is my searchform.php
Code:
&lt;form action=&quot;/search&quot; method=&quot;get&quot; role=&quot;search&quot; id=&quot;searchform&quot;&gt;
    &lt;div class=&quot;input-group&quot;&gt;
        &lt;input type=&quot;text&quot; name=&quot;s&quot; id=&quot;search&quot; class=&quot;form-control search-bar&quot; placeholder=&quot;Search Healthkart Blog&quot; value=&quot;&lt;?php the_search_query(); ?&gt;&quot;&gt;
        &lt;div class=&quot;input-group-append button-icon&quot;&gt;
            &lt;button class=&quot;btn&quot; type=&quot;button&quot; id=&quot;searchBtn&quot;&gt;
                &lt;img src=&quot;&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/assets/images/search-icon.png&quot; alt=&quot;search&quot; class=&quot;search-icon-white&quot;&gt;
                &lt;img src=&quot;&lt;?php echo get_stylesheet_directory_uri(); ?&gt;/assets/images/search-icon-grey.png&quot; alt=&quot;search&quot; class=&quot;search-icon-grey&quot;&gt;
            &lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/form&gt;
I have included it in header.php as
Code:
get_search_form();
And the JS for submitting the form in this way
Code:
$(&quot;#searchBtn&quot;).click(function(){
    $(&quot;#searchform&quot;).submit();
})
I have also created a custom search result page called search.php and it contains the normal search page code. Then I have created a page in wordpress pages called search (URL as /search) and assigned the custom search result template to it.
The issue is when I submit the form, it gets redirected to /search/?s=test123 and returns a 404 page. But if I hit the urls /search/test123, it works.
How do I make the search form submit to the URL /search/test123 ?