0

How can i change the url plus(+) sign to dash(-) in url with htaccess. This is the code i have so far:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /(#[^?&\ ]*)?\?([^&\ ]*&)?s=([^&\ ]+)[^\ ]*\ HTTP/
RewriteRule ^$ http://example.com/search/%3\.html? [R=301,L]
</IfModule>

This works well and the result something like this: http://example.com/search/key+word.html

The only thing is that i want to change plus with dash. I would really appreciated if anyone can help out.

panjianom
  • 236
  • 4
  • 18
  • I'm not having a go, or telling you what to do, but wouldn't that take away the main point of a search string? it's showing a plus to show you that its searching for this word AND this word AND this word? – Lee Sep 11 '14 at 07:53
  • The purpose of this string is for SEO and it's still showing the results for this word AND this word AND this word because I update the query.php file too. Thanks anyway – panjianom Sep 11 '14 at 08:30

2 Answers2

2

You can insert this code just below you 301 rule:

RewriteRule "^(search)/([^ +]*)[ +]+([^ +]*[ +].*)$" /$1/$2-$3 [L,NE]
RewriteRule "^(search)/([^ +]*)[ +]([^ +]*)$" /$1/$2-$3 [L,R=302,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643
0

I decide to make it possible by using plugin with this code:

function seo_search_result() {
    if ( is_search() && strpos($_SERVER['REQUEST_URI'], '/wp-admin/') === false && strpos($_SERVER['REQUEST_URI'], '/search/') === false ) {
        wp_redirect(get_bloginfo('home') . '/search/' . str_replace(' ', '-', str_replace('%20', '-', get_query_var('s'). '.html')));
        exit();
    }
}

add_action('template_redirect', 'seo_search_result');
panjianom
  • 236
  • 4
  • 18