Hack Your Own Site for Simpler Searching
January 30th, 2008 · by David Bradley
Fellow blogger Alex King is an exceptionally talented guy, he never ceases to amaze me with his adeptness in creating new, and more important useful plugins for the likes of Wordpress and for making the most of some of the simplest little hacks.
He recently posted a hack for your .htaccess file (you have to have Apache hosting for your site or blog for this to work). The hack makes searching your site very straightforward via a URL rather, but also simplifies the results address produced by your inline search box.
First, make a backup of .htaccess, then add the following
RewriteRule ^search/(.+)?$ /index.php?s=$1 [QSA,L]
to your .htaccess file and save the new .htaccess file.
To do a site search simply use a URL of the form www.yourdomain.com/search/your+search+terms
e.g. to search this site for “google tips” you would use the URL www.sciencetext.com/search/google+tips
As you can see, the search pulls up all the relevant results, but the URL for search results page is as it is, without the hack, the address is “http://www.sciencetext.com/?s=google+tips”. I think it’s much neater with that quasi search folder.
Alex goes on to add that you can modify the search form on your site so that the same kind of URL shows up when your visitors search: In your theme, simply add an “onsubmit handler” to the form tag for the search form, visit his site to get the skinny on that hack.


















4 responses so far ↓
That’s pretty cool! I need to learn some coding from Alex because there are quite a few plugins that I want to write! Thanks for the info!
Aseem, I do think Alex has some great plugins skills. Up and coming plugin writer Wayne Smallman (who contributes a lot here) is worth checking out at his technology blog. His recently launched Socialize Me! plugin runs on this site.
db
David Buchmann // Feb 21, 2008 at 5:56 am
I believe the article should read “…to search this site for Google tips…” instead of “Firefox hacks”.
-David-
Well spotted David, I must have changed my mind half way through the editing process but failed to tweak the search string. You could of course, mod the string and search for the plethora of Firefox hacks on this site too
db
Leave a Comment