Jump to content
Larry Ullman's Book Forums

Mod_Rewrite Does Not Replace Spaces In Url To Plus (+) Symbol Or Hyphen (-)


Recommended Posts

Hello people, I am attempting to send the $row['name'] value retrieved from my database which contains spaces, however Mod_Rewrite Does Not Replace Spaces In URL To Plus (+) Symbol Nor Hyphen (-), anyone know how to fix this ?

 

here is my url to send to match my url in mod_rewrite:

<a href="/html/browse/' . $type . '/' . $subcategory . '/' . $row['name'] . '/' . $row['id'] . '" class="button">view product</a>

 

here is my rule in mod_rewrite :

 

RewriteRule ^browse/(clothing|jewellery|accessories)/([A-Za-z]+)/([A-Za-z]\+\-]+)/([0-9]+)/?$ viewitem.php?type=$1&subcategory=$2&name=$3&id=$4 [L]

 

Thanks in advance. :)

Link to comment
Share on other sites

thanks for your reply hartley, i did try that regex but it didn't work, this is what i done, the rule i created for variable $row['name']  above was this ([A-Za-z%20]+), it didn't work, so the way i have it working now is by creating a str_replace function, $new_string_replacing_spaces_with_hypens = str_replace('  '  '-'  $row['name']); and rewriting my mod_rewrite rule to ithis ([A-Za-z-]+)

 

it works but surely it should be easier than to invoke the string replace function ?

 

thanks people.

Link to comment
Share on other sites

 Share

×
×
  • Create New...