user756659
user756659

Reputation: 3512

seo friendly url rewriting with multiple parameters

I have a database full of physical locations along with their address information and want to use SEO friendly urls.

I'd like to turn this :

example.com/locations/?state=California&city=Los+Angeles&name=The+Name

into this :

example.com/locations/California/Los+Angeles/The+Name/

I have the following to work with :

id - unique
state
city
name - unique

What I have working with a single id parameter. I am not sure about handling multiple parameters especially considering state, city, and name are pretty open as far as allowed characters. Also, the urls should be encoded - ie 'Los+Angeles' comes in, but I will decode this to 'Los Angeles' when making my db query.

# redirect "/locations/?id=xxx" to "/locations/xxx"
RewriteCond %{THE_REQUEST} \s/locations/\?id=([0-9]+)\s [NC]
RewriteRule ^ /locations/%1/? [R=301,L]

# internally rewrite "/locations/xxx/" to "/locations/?id=xxx"
RewriteRule ^locations/([0-9]+)/$ /locations/?id=$1 [L]

Side thought... do I need to handle both + and %20 or is it my choice? One better to go with than the other?

Upvotes: 0

Views: 14

Answers (0)

Related Questions