Thinking of relative paths
When text editing pages from the administration end the paths inserted using the build-in word-processor for images and links are likely to be relative to the server. So if your server is located at http://www.example.com and your administrator is at http://www.example.com/admin/ then inserting an image sample.jpg in the images folder will end up in the database with a relative path ie: images/sample.jpg instead of http://www.example.com/images/sample.jpg.
You may wonder if this is a bug or not. The truth is by having the word-processor processing the HTML content, the browser now associates the paths with the base of the document. So properties like the src or href are now translated by the browser and relative paths are generated.
Now some people want to change this behavior and they edit the HTML directly or deploying code to change all of the links in the database. These methods may work but they are not ideal in terms of management. It takes time to edit the HTML manually, you can create errors in the process an break the template and even setting up a script to do that automatically you can never be sure if all references were altered properly.
A simpler method is to modify the administration configuration file (admin/includes/configure.php). Setting up a different Admin Server via the HTTP_SERVER definition can resolve this issue. For example if instead of http://www.example.com we populate the definition with 127.0.0.1 then every time we use the word-processor setting up links or images to http://www.example.com the content stored in the database will include the absolute paths as the browser sees a different server address.
Where this approach can be useful? Well it can help when you use common images like our online demonstration does where the different templates are located in sub-folders and the site content is still on a primary domain. There is no replication of images and therefore we can reduce the server bandwidth.
The disadvantage of using absolute paths is that if we need to change the domain at some point the entries in the database have to also change. In which case we will need to write a script to accomplish that.
This issue applies to the build-in editor only. Images or Links generated by the core functions aren't affected as the scripts consult the configuration files using absolute paths when necessary and generate the HTML based on the server setup.
There are no comments on Thinking of relative paths
This topic consists of articles that describe the project development cycle, milestones and future plans for the I-Metrics CMS.



