daviddawn Posted December 15, 2014 Share Posted December 15, 2014 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 More sharing options...
HartleySan Posted December 15, 2014 Share Posted December 15, 2014 I believe spaces in URLs get turned into %20. Maybe add that to your regex? Link to comment Share on other sites More sharing options...
daviddawn Posted December 15, 2014 Author Share Posted December 15, 2014 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 More sharing options...
HartleySan Posted December 16, 2014 Share Posted December 16, 2014 Somewhere in your script, run the following: echo '<pre>'; print_r($_SERVER); echo '</pre>'; Pay attention to the the request URL parameters, and compare them. They should reveal the actual URLs being used, and from there, you can hopefully resolve the issue. Link to comment Share on other sites More sharing options...
Recommended Posts