Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
daviddawn

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. :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...