Topic: Help with porting a php site
I'm doing a project where I have to port an existing php site that consists on an administrator backend kept neatly in a folder and then all the pages of the site are strewn about in the site root.
There are a lot more files then I showed there, I put the ... to save space. I'm not really concerned about how to port the admin backend as it is a rather straightforward process, what I'm confused about is how to handle all the .php files in the site root. See, the client has a few requirements about how all the pages are supposed to work:
1. All activity on the site has to be tracked e.g when a user hits the easter.php page, the username and the page they hit needs to be logged somewhere.
2. All the files have to be kept physically on the site (not have their content dynamically drawn in from a database) so that they can be edited by people using ftp & dreamweaver to make quick content changes on pages.
3. The client would prefer that they be kept in the site root or at least as subdirectory in the site root (in rails terms meaning that they should be put in app_name/public.
4. Some pages do have dynamic areas where the content changes based on who is currently logged in and what permissions that user has on the site. So this requires the whole rails stack to be loaded when these pages are displayed so that there is access to the models in the database.
So with these requirements in mind, the first solution I came up with was to take all the .php files in the site root and move them to rails_app_name/public. Rename them all to .rhtml files and put a bit of ruby code at the top of each file that logs the current user and the page name to the database. Then make a "pages" controller that defines a method_missing function:
def method_missing(call, *args)
# match the requested foo.rhtml and optionally any of the subdirectories
# it is stored in from the request and put it in $1
request.env['REQUEST_URI'] =~ /^\/pages(\/[\w\/]+)$/
# render the matching .rhtml file from public/
render :file => '/path/to/rails_app_name/public' + $1
To implement this solution I'm going to have to change every link in every file to add '/pages' to the front to trigger the pages controller. I'm not too concerned about the amount of effort this will take because it's just a regular expression applied to all the files. But what I am concerned about is if the client goes into one of the files and adds a new link, they are going to have to remember to put '/pages' in front of the path because otherwise it will just trigger a 404.
Does anyone have any ideas about how to avoid adding '/pages' to all the current and future links on the site? I have a feeling the solution lies in some fancy routing/url_rewrite rules, but I can't figure out how to do it. Or do you have any ideas about an easier way to solve this problem?
thanks for reading!
Zen and the Art of Motorcycle Maintenance