2

I've realized that Yahoo search doesn't correctly handle spaces in URLs.

When a user click to go to my website page that contains spaces, yahoo replaces them with '+' symbol.

My server doesn't correctly handle '+' instead of ' ', and generate 404 error.

So how can I replace '+' with ' ', using .htaccess?

Surfer on the fall
  • 721
  • 1
  • 8
  • 34
  • 1
    Why do the pages have spaces in the URL? I was under the impression that this is bad form for many reasons, including the one you are mentioning... – Matt Aug 13 '12 at 14:09
  • Sure, it's bad. But I can't change them. Any suggestions? – Surfer on the fall Aug 13 '12 at 14:12
  • How *does* your server encode spaces? Normally I believe they're encoded as `%20`, but if your server does it differently, it may be why Yahoo is replacing the spaces (it doesn't recognize them as such). – Matt Aug 13 '12 at 14:15
  • @Matt Yes, they are encoded as %20 and Google handles them perfectly. Perhaps Yahoo does some conversions. I need to replace '+' with ' '. – Surfer on the fall Aug 13 '12 at 14:17
  • 1
    What's the URL of the Yahoo search? – Matt Aug 13 '12 at 14:19
  • Something like this http://m.yahoo.com/apple/onesearch?p=key1+key2+key3&pintl=it&pcarrier=&pmcc=222&pmnc=10 ... and the url which Yahoo point to is /some+things+else.html ... Can you help me? – Surfer on the fall Aug 13 '12 at 14:29

1 Answers1

1

The + sign can be used to URL encode a space. It's been a part of the standard for ages and Apache 2 definitely knows how to decode a + to a space. What may be happening is the + is getting encoded itself as %2B, and you can change them to spaces using this:

RewriteEngine On
RewriteRule ^(.*)\+(.*)$ /$1\ $2 [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • Could you give an example of how you would fit that into something like this: RewriteRule ^client/([a-z0-9]+)$ index.php?client=$1 [L] – alanj Sep 17 '15 at 16:19