How to converting underscore to hyphens

Discuss practical ways rearrange URLs using mod_rewrite.

How to converting underscore to hyphens

Postby blu32008 » Fri Aug 22, 2008 12:21 pm

this is my code to rewrite my url for seo friendly

RewriteRule products-([a-z]+)-([0-9]+)-(.*)-([a-z]+)\.html products.php?on=$1&pid=$2&pt=$3&view=$4 [L]
RewriteRule products-([a-z]+)-([0-9]+)-(.*)\.html products.php?on=$1&pid=$2&pt=$3 [L]

when the script is execute, the result looks like this:

products-details-400-patriot_xporter_xt_boost_32gb_usb_flash_drive_180x_speed.html

the bold text is my product title -> $3.
How can i convert the underscore on $3 into hypens. Thx before
blu32008
 
Posts: 8
Joined: Thu Aug 21, 2008 10:32 am

Postby richardk » Sat Aug 23, 2008 10:00 am

What are the possible values of view? If you can't put them in the first rule you will have a problem working out if the last part is for view or pt.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby blu32008 » Wed Aug 27, 2008 8:05 pm

a-z only...so the view cannot be an empty values ?
blu32008
 
Posts: 8
Joined: Thu Aug 21, 2008 10:32 am

Postby richardk » Fri Aug 29, 2008 7:41 am

Yes. The problem is the optional view. One way would be to always have a view. Another would be to always put a - after pt even if there is no view.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 67 guests

cron