最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mod rewrite - seo friendly url rewriting with multiple parameters - Stack Overflow

programmeradmin0浏览0评论

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/locations/?state=California&city=Los+Angeles&name=The+Name

into this :

example/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?

发布评论

评论列表(0)

  1. 暂无评论