views:

534

answers:

3

I found this article regarding Url Rewriting most useful. But here are a couple of questions.

I would love to use a url (before rewriting, With spaces between the querry string)

http://www.store.com/products.aspx?category=CD s-Dvd s 

First of all, should i replace the spaces with the plus sign for any reason? (+)

http://www.store.com/products.aspx?category=CD+s-Dvd+s 

Secondly, my native language is Greek. Should i encode the parameters? General speaking, the result with url encoding - on, is different, regarding S.E.O.?

A: 

General practice is to replace spaces with underscores, ala http://www.store.com/products.aspx?category=CD_s-Dvd_s

ceejayoz
A: 

If the value must come through unaltered, then yes you must use escaping. In a URL query parameter value, a space may be encoded as + or %20. mod_rewrite will generally do this for you as long as the external version was suitably spelled.

In the external version of the URL, only %20 can be used:

http://www.store.com/products/CD%20s-Dvd%20s
http://www.store.com/products.php?category=CD%20s-Dvd%20s

because a + in a URL path part would literally mean a plus.

(Are you sure you want a space there? “CDs-DVDs” without the spaces would seem to be a better title.)

It is non-trivial to get arbitrary strings through from a path part to a parameter. Apart from the escaping issues, you've got problems with /, which should be encoded as %2F in a path part. However Apache will by default block any URL containing %2F for security reasons. (\ is similarly affected under Windows.) You can turn this behaviour off using the AllowEncodedSlashes config, but it means if you want to be portable you can't use “CDs/DVDs” as a category name.

For this reason, and because having a load of %20​s in your URL is a bit ugly, strings are usually turned into ‘slugs’ before being put in a URL, where all the contentious ASCII characters that would result in visible %-escapes are replaced with filler characters such as hyphen or underscore. This does mean you can't round-trip the string, so you need to store either a separate title and slug in the database to be able to look up the right entity for a given slug, or just use an additional ID in the URL (like Stack Overflow does).

bobince
A: 

Actually you should replace spaces with hyphens. That actually is better for SEO than using an underscore.

codejunky
And how do we know that?
ssg