• Hi,

    I’ve been testing my search with only one word and thought everything was working perfectly fine, until I did a search for 2 words: lorem ipsum. It returned me a 404 error upon clicking the Search Button.

    I’m using a URL Rewritting code to change the default ?s=lorem to a friendly /search/lorem

    However, it only works for single words. For multiple words, it doesn’t work!

    Here is my code:

    functions.php

    function search_url_rewrite_rule() {
    	if ( is_search() && !empty($_GET['s'])) {
    		wp_redirect(home_url("/".qtrans_getLanguage()."/search/") . urlencode(get_query_var('s')));
    		exit();
    	}
    }
    add_action('template_redirect', 'search_url_rewrite_rule');

    This works perfectly, I get redirected to http://dev.mycompany.com/mysite/en/search/tips

    searchform.php

    <form method="get" id="searchform" action="<?php bloginfo('siteurl'); ?>/">
    	<input type="text" class="field" name="s" id="s" value="" />
    	<input type="submit" class="submit" id="searchsubmit" value="Search" />
    </form>

    search.php
    See PasteBin: http://pastebin.com/5fL97HaP

    Note: I am using Relevanssi V2.9.10 plugin along with qTranslate.

    Example of what works:
    Typing tips returns http://dev.mycompany.com/site/en/search/tips
    Typing lorem returns http://dev.mycompany.com/site/en/search/lorem

    Example of what does NOT work (returns SERVER ERROR 404 Not found):
    Typing lorem ipsum returns http://dev.mycompany.com/site/en/search/lorem+ipsum

    Would it be the fault of the URL Rewriting?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter SpiritOfTheWinds

    (@spiritofthewinds)

    I have found the cause of why it doesn’t work. It seems that the WordPress search can’t handle my URL Rewriting. I do think it has to do with how WordPress decode the string when it is inside the URL since it returns “SERVER ERROR 404 Not found”.

    ?s=lorem+ipsum works
    /lorem+ipsum does not work

    Is there a way to make WordPress work with it?

    Thread Starter SpiritOfTheWinds

    (@spiritofthewinds)

    Actually, I found a workaround. I’m replacing the ‘+’ with a ‘-‘. I think it can’t take a + inside a URL, but can in a querystring. With a dash, it behaves like it should be.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Can't search with multiple words’ is closed to new replies.