I working on project that displays item according to the location. First time user has to pick a location in order to search for an item. This location is saved as cookie for future reference. The url looks as following:
www.example.com/newyork
If the user is looking at an item that exists in New York, the url for that item is:
www.example.com/item/iphone
Above url works fine but there is one problem. If the above url is forwarded through an email to a first time user, This item does not exist because the location is not selected. I could forward user to different page to select location and then look for the item, but this is hassle for the user. So, I would like to change above url to
www.example.com/newyork/item/iphone
so that way I could use New York as location. How do I add a non-existing sub directory to a url? Canthis be done with PHP or done with mod_rewrite?
You can try doing a redirect, but you’ll have to carefully craft the regular expression used to match
/newyork/item/iphone. Then you can group out thenewyorkpart and set a cookie and redirect the browser using theCOflag.This will take a request like
http://www.example.com/pittsburgh/item/iphoneand extract thepittsburghpart, store it in a cookie namedlocation(with the domain=example.com and path=/), then redirect the browser so the cookie gets stored by the browser and make the browser go tohttp://www.example.com/item/iphoneSee the documentation for the
COflag for details about the syntax: