Serving up static pages in CakePHP

Published by Subhas Fagu on 21/09/09 09:39:49
Last edited on 21/09/09 10:27:05

In every dynamicly driving project there must exist some static content. While there are dozens of ways of doing this, we here at Techlicity do it in one of 2 ways. If your looking to serve up strictly static html pages such as privacy policy, AUP or just simple static description pages then you might want to skip all of CakePHP preprocessing to realize that your content is static.

We suggest either having a subdomain to serve up your static content or just create a folder that CakePHP doesn't see.

Technique #1: The great thing about this technique is that it is easy to mantain, it makes it very easy to set permissions on developers vs static content editors. No preprocessing, just simple webserver file serving. You can even employ a light webservers to serve this content. Here is your chance to give LightTPD a try :D

 Technique #2: Using .htaccess to hide your static folder from CakePHP
Open up the .htaccess file that comes with cakePHP (located at the root level with app & cake folder)

 

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase / 
RewriteCond %{REQUEST_URI} ^/documents/(.*)$<br />&nbsp;&nbsp;&nbsp; RewriteRule ^.*$ - [L]
</IfModule>

We have just made the folder 'documents' hidden from CakePHP. Here you can now put your static files to be served as http://www.yourdomain.com/documents/mystatic_file.html

About the Author

Subhas Fagu is an energetic person who you will never catch doing the same thing twice…unless it’s working. He’s always engaged in new concepts, frameworks, operating systems, applications, you name it and you’ve got a conversation. Being a founder of Techlicity Ventures, he's been a key in the business and technical development of all previous and upcoming projects. Subhas contributes a wide variety of perspectives to all projects to ensure risk coverage and smooth deployment.

Bookmark and Share
Blog Widget by LinkWithin
blog comments powered by Disqus

Valid XHTML 1.0!