Clean Permalinks for Search Results

Here is a little tip to force WordPress to use clean permalinks for search results. Despite using pretty permalinks you may have noticed WordPress returns search results as yoursite.com/?s=SEARCHTERMS instead of yoursite.com/search/SEARCHTERMS. I'll show you how to achieve the latter.

First of all, create a new file called search.php which contains the following,

<?php header('Location: http://www.yoursite.com/search/' . $_GET['s']); ?>

Upload that file to root. Next, look in your theme's folder for the searchform. Change the action to,

action="<?php bloginfo('url'); ?>/search.php"

All done. Test it out for yourself. Type the term WordPress in the search engine and look at the URL.

Further reading:

http://codex.wordpress.org/FAQ_Advanced_Topics

About the author
Len has been blogging for over 10 years and is a rabid WordPress fan. In addition to blogging here you can find him writing the occasional article and toiling away in the forums at WeblogToolsCollection.com. He also hangs out at the WordPress support forums lending a hand where he can. You can also find him at his other blog LenKutchma.com

Leave a Reply

CommentLuv Enabled