Modify WordPress search result URL using .htaccess file

I’m currently experimenting with a WordPress website that uses a modified search.php file to show dynamic web pages.

When a search term is entered it produces a URL similar to:

Read More

example.com/?s=search+term

Is it possible to add a rule(s) to my .htaccess file that changes the result URL into something more friendly without effecting the search.php function? Eg:

example.com/search-term

or, even better:

example.com/BLOG NAME/search-term.html

Related posts

Leave a Reply

2 comments

  1. I don’t think you can achieve this without .html or any other trick, because by default WP uses clean URLs for posts, so you can’t mess the functionality, but you can do something like this:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /blog_name/
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ([^/]+).html$ ./?s=$1 [L]
    </IfModule>
    
  2. I use pages (ie. not posts) that are setup as children of a parent page. In my menu bar navigation they appear as

    /services/page1.html
    /services/page2.html
    /services/page3.html