Space to hyphen, and then...?

I read a lot about url rewriting and SEO aspect of hyphen vs underscore. As you alredy know, hyphen is preferable for space replacement.

Using underscore instead od space is easy - underscore is not part of normal words, so it can be easily removed (replaced with space) before querying a database.

Using hyphen instead od space put question about querying a database. Hyphens can’t be removed (replaced with space) through hyphenated words existence.

What’s the best solution - explicitly store the hyphenated names (“brand-name”) in the database or something else?

That’s what I meant, not to store just value with hyphens. I’m thinking of some other solution, some real-time replacement if possible.

Thank you! Actually, I’m here for many years (8 at least), but I’m not so comfortable writing english and can’t be helpful to other, so I just read. :slight_smile:

I didn’t say that hyphen is better then underscore as space replacement, just it’s preferred way according to Google (Webmaster Central Blog, Matt Cutts…) and most od SEO and usability experts. I really agree with you, especially because I have habit of using underscores, but my opinion vs Google opinion… :slight_smile:

Also, be sure I have read your great tutorial, there I learnt how to rewrite unlimited key/value pairs! :slight_smile:

dacha,

First, WELCOME to SitePoint’s Apache forum!

Second, I disagree with the - being preferred over _ when replacing spaces in your links. This is covered in my signature’s tutorial Article.

Regards,

DK

Yes, but… :slight_smile:

I alredy knew that, but as everybody talk about hyphen as better choice and no one indicate this issue, I was thinking that I’m missing something, some easy way to solve it.

So, we can say that there are two solutions - using underscores with on the fly replacing or using hyphens and store original and hyphenated values.

dacha,

Fair enough. IMHO, there is only one VALID solution but that’s my personal preference. I’m just not going to ever be convinced that -'s are better than _'s OR that SEO’s would ever believe that to be the case.

If you’d like, I can move this thread to SitePoint’s SEO forum board so you can get some less biased (and less experienced, IMHO) opinions.

Regards,

DK

dacha,

Gudonya! You not only understood but provided an example of WHY -'s are NOT a good solution to this simple problem! :tup:

Regards,

DK

If you want to go from a string with spaces to a string with hyphens you could do it on the fly, however you might as well just store the hyphenated string in the db to save on the extra legwork.

And if you retain the original spaced version that you can always use the one you need. I don’t really understand the issue, perhaps you will need to add a bit more explanation?

store two versions - the value with hyphens and the value without, then compare.

I’ll try to explain…

If I decide to use underscore for space replacement, i can store just original string (with spaces) and do the rest on the fly:

brands

Schweppes
Coca-Cola
Red Bull

(1) when building URL: replace all spaces with underscores

[INDENT]Schweppes
Coca-Cola
Red_Bull[/INDENT]
(2) when building sql query: replace all underscores with spaces

[INDENT]Schweppes
Coca-Cola
Red Bull[/INDENT]

That’s it.

That’s not possible with hyphens because some original strings contain hyphens and step (2) would produce inaccurate results:

(1)

[INDENT]Schweppes
Coca-Cola
Red-Bull[/INDENT]
(2)

[INDENT]Schweppes
Coca Cola (wrong)
Red Bull[/INDENT]

I asked for some solution that I can store just original string values, and use hyphen for space replacement.