#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    5

    .htaccess Question regarding _ ?


    Hi Everyone,

    My htaccess isn't account for spaces with certain keywords. I'm not sure why because I thought my syntax was correct but it turns out it's wrong.

    A URL like this one on my website is working. It's working because there are no spaces in between keywords.
    http://mysite.com/florida/orlando/2006/ford/explorer

    A URL like this on my website is working but I don't want the %20 in between any keywords.
    http://mysite.com/florida/key%20west/2005/ford/explorer

    My goal is to take the second above URL (the one with a space) and make it look like this below URL
    http://mysite.com/florida/key_west/2005/ford/explorer

    or take a URL like this
    http://mysite.com/rhode%20island/north%20providence/2005/ford/explorer

    and turn it into this
    http://mysite.com/rhode_island/north_providence/2005/ford/explorer

    How would I do that?

    My .htaccess code is below.

    Code:
    RewriteEngine On
    RewriteRule ^([_a-zA-Z_]+)$ state.php?state=$1 [L]
    RewriteRule ^([_a-zA-Z_]+)/([_a-zA-Z_]+)$ city.php?state=$1&city=$2 [L]
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /make-model.php?state=$1&city=$2&year=$3&make=$4&model=$5 [L]
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    You would fix that in whatever generates the links, not in your .htaccess.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    5
    Originally Posted by requinix
    You would fix that in whatever generates the links, not in your .htaccess.
    I understand what your saying requinix but I'm pretty sure that's already accounted for because my make-model.php there is syntax that supports spaces. I'm using the str_replace function.

    PHP Code:
    $state str_replace (' ','_'$state);
    $city str_replace (' ','_'$city); 
    $model str_replace (' ','_'$model); 
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    Well mod_rewrite certainly isn't the one adding those spaces/%20s in...

    Is there a chance that those variables are being (raw)urlencode()d before that point?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    49
    Rep Power
    5
    Originally Posted by requinix
    Well mod_rewrite certainly isn't the one adding those spaces/%20s in...

    Is there a chance that those variables are being (raw)urlencode()d before that point?
    Is there a chance that those variables are being (raw)urlencode()d before that point?
    Hi requinix,

    No, I'm not using the urlencode php function.

    Thanks for the reply. The keywords/key-phrases are being extracted from a mysql database.

    For example, New York is stored in my mysql database as New York and same-thing with every state and city. They all have spaces in the database.

    New York > Long Island
    Rhode Island > North Providence
    etc .....

    Happy New Year and thanks for your help!
  10. #6
  11. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    I believe your thought order is out of order.

    1. PHP gets info from database
    2. PHP makes URL/link from info
    3. User clicks link to URL
    4. RewriteRule rewrites URL

    If you don't want spaces in your URL/link, that's a PHP issue. When PHP createst the link, it needs to convert the spaces to underscores.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.

IMN logo majestic logo threadwatch logo seochat tools logo