Forum Moderators: phranque

Message Too Old, No Replies

Create SEF URLs from URLs that contain commas, spaces, others

Query string contains commas, spaces, and others

         

bigwebidea

10:18 pm on Jul 29, 2009 (gmt 0)

10+ Year Member



I've used the following thread - [webmasterworld.com...] - to successfully create dynamic to static urls.

Some of my urls have commas and spaces in the query string.

Example:
http://example.com/folder.php?product=These are, keywords

which results in:
http://example.com/folder/These are, keywords

How can I change the commas and spaces or other characters to hyphens?

[edited by: jdMorgan at 11:00 pm (utc) on July 29, 2009]
[edit reason] example.com [/edit]

jdMorgan

11:00 pm on Jul 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



One way is to use the PHP preg_replace function.

But after you do that, and the visitor clicks on a link "example.com/folder/These-are-keywords" your mod_rewrite code will rewrite that to the path "/folder.php?product=These-are-keywords", and you will need to use relatively-complex PHP code to find a "best match" for that hyphenated version in the database if the database still contains/uses the "These are, keywords" format.

So your best bet is to fix this in the database itself.

Sometimes site owners just choose to edit the "These are, keywords" entry itself. Sometimes they choose to create and additional entry, so that the product and/or page description becomes a separate item from the string used in the URL. Wearing both a coder hat and an SEO hat, that is what I would do. In fact, I'd make just about *everything* a separate value in the database record for a product, and if I really felt I needed to re-use the exact same text for page description, product description, and keyword-URL-string, I'd do a copy and paste inthe database entry form, and so be it.

Jim

g1smd

7:27 pm on Aug 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That's a good approach. I do roughly the same thing. If a title is going to be used as part of a URL, then punctuation is sanitised, replaced, or removed, and spaces are converted to periods or hyphens and this is then stored as a separate entry.

bigwebidea

7:20 pm on Aug 2, 2009 (gmt 0)

10+ Year Member



Great, that's what I'll do then. Thanks for the advice. I have another question - using the implementation found here - [webmasterworld.com...] how do add a .html extension?

jdMorgan

9:13 pm on Aug 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can add .html to the URL on your pages, and remove it when rewriting to your script. But there is no good reason to do so. Quite the contrary, actually -- waste of characters, CPU time, and bandwidth, and to an extent, it "locks you in" to a particular technology (e.g .html, .php, .cf).

Because of that, you'll find several contemporary threads here about getting rid of extensions.

Jim