I am rewriting our company website in cakephp, and need to find a way to do the following:
- A user enters our site by using one of the promotional alias URLS that has been pregenerated for a specific media advert ( magazine, web promotion etc )
- The URL is checked against a database of alias URLs, and if an alias exists, then a specific tracking code is written into the session.
I have considered several options, none of which seem suitable for this purpose. They are:
- Putting the lookup script in the
beforeFilter() in appcontroller, so
that its included in every
controller. (Writes a session value
so it only perfoms once.)
- This option only works for existing contollers, and gives the Cake 'missing controller' error if a URL doesn't exist.
- Specific routes for each alias in Routes.php - Works but there are potentially hundreds of alias urls added/removed regularly via admin interface.
- Route all site URLs to their own actions, and having an 'everything else' rule, for the alias URLs that maps to my lookup script. - Messy and I lose the built in Cake routing.
- Custom 404. - I don't want to return 404's for these urls, as I feel its bad practice unless they really don't map to anything.
I really could do with a place in the application flow where I can put this lookup/tracking script, and I'm fairly new to cake so I'm stumped.
EDIT: Also, I know that a subfolder called say 'promo' would easily do this, but I have a lot of legacy URLS from our old site, that need handling too.