Nice Search
This is a really simple plugin that redirects your WordPress searches (?s=search-term) to the pretty-looking URI version: /search/search-term, and also converts spaces (%20) to plus symbols.
Obviously, you need to have mod_rewrite enabled, so that WordPress can process the /search/ style URIs.
This plugin requires WordPress version 1.5 or higher.


Mark, how would the entry on .htaccess for this looks like? I am using an old version of WP and my search box looks like:
" />
My .htaccess search entry looks like:
RewriteRule ^search/([/_0-9a-z-]+)/?$ /index.php?s=$1&submit=search [QSA]
If I enter the search on the URI like http://www.collantes.us/search/XPS, it works, but if I use the existing search box it renders the old search results style.
Your version of WordPress lacks the necessary hook. Also, your .htaccess mod_rewrite code seems to redirect instead of rewrite when a CAPS search term is used. You might have to add A-Z in that rewrite rule.
Ahh, rats! Thanks Mark! One day, it will come…
Hi Mark,
Your plugin makes something possible I desired very much: to be able to search in my Ultimate Tag Warrior tags (I call them keywords) by replacing the /search/ folder in your plugin by /keyword/. It even allows boolean tag1 and/or tag2 search this way. Thanks for that.
But what I would like most is to have two search forms, one normal Wordpress search with the ‘nice search’ URI as the result. And one which allows the boolean search in my tags.
I’m no coder so I can only choose between these options (OR) and hope you can think of a way to include both searches (AND) at my sites.
Regards, Gerard
Gerard,
You would likely have to make changes to the script that would change the type of search based on a radio button selection in the form. One radio button could be called “use_search” and the other could be called “use_tags” and then you could test for
$_GET['use_search']or$_GET['use_tags']and redirect accordingly.This is a great plugin. It works very well. But when I search for something with 2 keyterms and a space in between, eg. “wordpress plugins” the URL becomes
http://siteurl.com/search/wordpress%20plugins
Is there a way to change the %20 to a dash or something?
Thank you.
Just a problem here, after I change the permalinks of search page, I get a 404 error when I do a search, any idea how to fix it? It works after I changed the permalinks back to the old one.
What do you mean “change the permalinks of search page”? In WP, search isn’t really a page, it is a
$_GETparameter ($_GET['s']).I’ve created a search page with this in the page
At first it works when the permalink to the seach page was
http://siteurl.com/category/search/
but after changing it to
http://siteurl.com/search/
all searches resulted in 404 errors when I do a search with the plugin enable, after changing back to the old slug for the search page, this plugin works again. Any idea how to fix it for the new slug?
Thank you.
sorry, my code didn’t turn up well..
the code is
TEMPLATEPATH . ‘/searchform.php’
in php
Give me a link to your site, and I’ll take a look at it.
Thank you.
Link to search page:
http://liberta.espoireve.com/search/
Example of a search:
http://liberta.espoireve.com/search/test
Aha! The problem there is that you have a WordPress page called “search.” This is “intercepting” the
/search/part of search URIs and breaking them. If you rename the “slug” for your search page to something likesearch-formor something other than “search,” the problem will be resolved.Right, is it possible to have the slug of the search page as search but change the URL of the search into
http://siteurl.com/searchresults/test
?
Yes, that’s possible, but it’d require a plugin to do it… and it would be different depending on whether or not you used WP 1.5.x or WP 2.x
Right, I understand will just stick to the current one now.
Referring back to http://txfx.net/code/wordpress/nice-search/#comment-12078
this comment, is there a way to change the
wordpress%20plugins to wordpress+plugins?
Thank you for being so patient with me.
You can change the %20 to a dash by using the WordPress function “sanitize_title”. Replace
$_REQUEST['s']withsanitize_title($_REQUEST['s']). Also, you can add a trailing slash with this:** . '/'Great plugin, Mark.
Some of that code didn’t copy well. Here’s another try:
sanitize_title($_REQUEST['s']) . ’/’
One more thing (sorry for so many comments, Mark): The sanitized title removes apostrophes and other characters, so you can’t search for words like don’t or can’t.
Also, my copying attempt from last time still didn’t completely work because WordPress doesn’t like lots of slashes. Oh well.
I am trying to make a beautiful search bar like yours without the big space and submit button that is in wordpress. I have downloaded the plug-in. What is the call for yours and do I need to change the css?
Just found a little bug in your plugin:
I use the WP-Paginate Plugin. If i go to page 2 and then go back to page one, the $_GET['s'] has a slash at his end. So wordpress is searching for a+searchstring/ and finds nothing.
Just fixed it very simple with the following code. Just put it into your plugin and it works
function replace_search_slash() { if(!empty($_GET['s'])) { $_GET['s'] = str_replace(’/', ”, $_GET['s']); } } add_action(’init’, ‘replace_search_slash’);And also a big thank you for this wonderfull plugin.
I have “Nice search” working on one of my sites (very nice!) and now I am trying to implement it on a Yahoo Hosted site.
The strange fact is that using a search through the regular search box generates the “old” URL with “/index.php?s=test” and gives a 404.
If I manually use the “/search/test” sting in the browser the correct results come up.
Nice work on this.
I wanted to point out for your next update on it that you should really not hardcode “search” in there since Wordpress has had the ability (since 2.0?) to change the search path for the internal regex. You can query the new path. In 2.1 it will be editable right in the panel.
Also I try to prevent redirects from even being needed by adding this onsubmit in the hopes that most users will have javascript enabled:
'+document.forms["searchform"].s.value.replace(/ /gi,’+');”>
I believe we both need to replace “/search/” with $wp_rewrite->search_base.”/”
This will help with foreign languages and if someone wants to rename it to searchresults or find or something else weird
Keep up the great work…
sorry, your setup trashed my little strip of code
lets try it this way
(and remove all the newlines)
Hello, what should I do to have a /find/ instead of a /search/?
Hi! It’s an excellent plugin! Thanks for this. I would use it.
But I have any trouble: the plugin remove non-ASCII letters. It’s problem.
F.e. in my language (Czech), ther’re a letters with diacritic marks. And the result of plugin is like this:
/search/růžový — > remove 3 letters — > results: /search/rov
Can I correct it somehow?
Great plugin, only one issue for me: Using WP 2.0.5, on the search results page it says “Search Results for:(blank)” where (blank) should be the terms searched for.
I’m using the sandbox theme http://www.plaintxt.org/themes/sandbox/ . Not sure if this is why, I’m a bit of a newbie with this all.
These two urls are the same:
http://www.site.com/search/term
http://www.site.com/search/term/
Is there anyway to force one or the other, preferably the one with the trailing slash?
This may be a quirk that’s specific to my host, but activating this plugin has some strange effects for me. Every search leads to a page with the title “200 OK” and the following content:
The word “here” is a link that will take the searcher on to the properly-redirected page. “200 OK” is the Apache status code that means the resource was found, so I can’t figure out why I’m getting this message at all. Could this be related to this similar bug report for a different plugin?
I also used to get the same thing when I was still using Alex King’s Popularity Contest plugin (when resetting comment/ping counts). Since visitors never saw that message, I didn’t worry about it.
I’ve posted a similar message to this one on my host’s forum. If this turns out to be a server configuration issue, I’ll bring you the details.
good plugin!
but not work with utf-8 …
I’m a real newbie with WordPress, as i am with most of the internet, but I’m going to give this a go. I’ll let you know how I get on with it.
thanks
Great plugin, only one issue for me: Using WP 2.0.5, on the search results page it says “Search Results for:(blank)†where (blank) should be the terms searched for. ??
Forget it… I did it.
The subpage already shown…
Installed plug-in on one of my blogs and see that it looks very pretty and useful for blog exiting.
Hi, I’m running WP 2.2.2 I downloaded your nice-search file and activated the plugin but I get this error when doing a search:
Warning: Cannot modify header information - headers already sent by (output started at /home.9.13/mydomain/www/blog/wp-content/plugins/nice-search.php:1) in /home.9.13/mydomain/www/blog/wp-includes/pluggable.php on line 331
Any idea what’s the problem? Thx!
thanks to your plugin, but i have the same problem like this:
http://txfx.net/code/wordpress/nice-search/comment-page-1/#comment-35667
i’m a chinese, so we do searching with many non-ASCII characters, when we search them, eg. 䏿–‡, we got a 404 page.
Nice little Plugin. Thanx for that !
Great plugin. I have one question: Can you make it so a URL like http://example.com/search/ points to something useful (like a search form or page), rather than return a 404? As you mentioned above, creating a page with the slug ’search’ intercepts the plugin. But not having a page with the simple /search/ URL messes up the beauty of the nice URLs.
thanks
Thx for plugin
thank you
Thank you
thanks
Thanks for plugin…
Thanks it is worth to try,get rid of annoying signs with a simple htaccess line.
Thank you for your useful plugin! this help me a lot on my blog!
This is a great plugin as well. This has really helped me out. thanks so much.
thank`s nice man very intresting
very intresting
i have tested the plugins, works ok
Great plugin.
I would like to change the /search/ part to something else. Like /s/
Is this possible? I noticed it was not just a matter or rewriting the url in the code.
Thanks.
Hi Mark, great plugin, I would like to change the /search/ for the spanish word /buscar/. What should I change?
Thanks in advance….
youre effort means allot for us.. and the plugins you have for us are just great.. thanks!
Hi there,
Please can you advise how I can install this plugin on my site.
Regards. John.
thx for this site…great job
Thank you.
Link to search page:
http://liberta.espoireve.com/search/
Example of a search:
http://liberta.espoireve.com/search/test
Great Post!!!
Manele noi