I have a custom Map with tiles generated using Google's XYZ co-ordinate system. There are 2 applications that need to consume the tiles - both are out of my control. One of them requests the tiles in the same XYZ co-ordinate system they are saved in - but the other app requests them using the TMS co-ordinates which results in a request for a different filename.

The map tiles are requested using a URL that starts with a subdirectory for the zoom level, followed by a Y co-ordinate as a subdirectory and finally an X co-ordinate which is a filename. It is the filename that is different for each co-ordinate system since one starts numbering tiles in the top left corner of the grid and the other starts in the bottom left. I believe there is a simple formula that can be used to convert between the 2 co-ordinate systems.

So...I currently have my map tiles stored in the native XYZ directory structure in which they were generated - and apps can request the tiles using the following style URL:
http://server/mapdata/x/y/filename.png

What I would like to do is to create a second URL which looks like: (adds the tms)
http://server/mapdata/tms/x/y/filename.png
...and when this URL is used, I'd like to trigger a formula which translates the incoming TMS filename (a 6 digit numeric value) to the correct equivalent XYZ filename and then rewrites the entire URL to match the one in the first paragraph above.

I'd actually be really surprised if something like this did not already exist - but I've spent a couple of hours searching and can't find what I need.

My only other alternative is to download a batch file rename tool and make a second copy of all of my map data that is stored with the alternate file names - which seems like a big waste of time and disk space.

I'm open to other suggestions that will make this work - as long as the suggestion is not "ask both consumers of the data to use the same co-ordinate system for their requests".

Thanks in advance for anyone that can point me in the right direction...