I'm looking for some advice for the following scenario: We will have a site for a company with multiple locations throughout the US. Some of the pages are specific to a certain office location while other pages are generic for all locations.
I'm thinking of creating a page structure like this:
- Home (Generic) - Locations - New York (This would be the New York office home page) - About US (Specific to the New York location) - Contact (Specific to the New York location) - Los Angeles - About US (Specific to the Los Angeles location) - Contact (Specific to the Los Angeles location) - ... etc ...
When a user enters the website I want to guess their approximate location based on their IP address. Based on their location they should end up at the nearest office location home page, so for example /locations/new-york
.
I'd want to set a session var when it doesn't exists yet containing the selected location so that I can redirect subsequent page requests to a sub page of that location.
My main question is how to handle the routing on subsequent requests. Say I have a session value and it contains the slug of the selected location:
$_SESSION['location'] = 'new-york'
The user is requesting the Contact page: http://example.com/contact
What hook would I need to use to be able to rewrite that URL to http://example.com/locations/new-york/contact
in case the session var is set?