The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> System Administration
> Apache Development
|
.htaccess Question regarding _ ?
Discuss .htaccess Question regarding _ ? in the Apache Development forum on Dev Shed. .htaccess Question regarding _ ? Apache Development forum discussing HTTP Server general topics, configuration, and modules. Apache is an open source web server that runs on multiple platforms.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 31st, 2012, 01:24 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 49
Time spent in forums: 5 h 34 m 35 sec
Reputation Power: 4
|
|
|
.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]
|

December 31st, 2012, 01:30 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
You would fix that in whatever generates the links, not in your .htaccess.
|

December 31st, 2012, 01:46 PM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 49
Time spent in forums: 5 h 34 m 35 sec
Reputation Power: 4
|
|
Quote: | 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);
|

December 31st, 2012, 03:00 PM
|
 |
Still alive
|
|
Join Date: Mar 2007
Location: Washington, USA
|
|
|
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?
|

January 1st, 2013, 10:33 AM
|
|
Contributing User
|
|
Join Date: Aug 2009
Posts: 49
Time spent in forums: 5 h 34 m 35 sec
Reputation Power: 4
|
|
Quote: | 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? |
Quote: | 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!
|

January 3rd, 2013, 02:56 PM
|
 |
mod_dev_shed
|
|
Join Date: Sep 2002
Location: Atlanta, GA
|
|
|
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|