How to rewrite these URLs?
Posted
by
Evik James
on Server Fault
See other posts from Server Fault
or by Evik James
Published on 2012-06-16T23:01:58Z
Indexed on
2012/06/17
3:19 UTC
Read the original article
Hit count: 460
I am brand new to URL rewriting. I am using an Apache rewriting module on IIS 7.5 (I think). Either way, I am able to do rewrites successfully, but am having trouble on a few key things.
I want this pretty url to rewrite to the this ugly url:
mydomain.com/bike/1234 (pretty)
mydomain.com/index.cfm?Section=Bike&BikeID=1234 (ugly)
This works great with this rule:
RewriteRule ^bike/([0-9]+)$ /index.cfm?Section=Bike&BikeID$1
Issue #1
I want to be able to add a description and have it go to exactly the same place, so that the useful info is completely ignored by my application.
mydomain.com/bike/1234/a-really-great-bike (pretty and useful)
mydomain.com/index.cfm?Section=Bike&BikeID=1234
Issue #2
I need to be able to add a second or third parameter and value to the url to get extra info for the db, like this:
mydomain.com/bike/1234/5678
mydomain.com/index.cfm?Section=Bike&BikeID=1234&FeatureID=5678
This works using this rule:
RewriteRule ^bike/([0-9]+)/([0-9]+)$ /index.cfm?Section=Bike&BikeID=$1&FeatureID=$2
Again, I need to add some extra info, like in the first example:
mydomain.com/bike/1234/5678/a-really-great-bike (pretty and useful)
mydomain.com/index.cfm?Section=Bike&BikeID=1234&FeatureID=5678
So, how can I combine these rules so that I can have one or two or three parameters and any of the "useful words" are completely ignored?
© Server Fault or respective owner