0
votes

I'm make a static/dynamic mixed site.

  1. if a user accesses to xxx.com/about, I want to use pages controller to show about.ctp. it seems it's done like /pages/about but if i want to hide /pages, do I have to write like:

Router::connect('/about', array('controller' => 'pages', 'action' => 'display', 'about'));

for all static pages? or any better way?

  1. some static pages may be hierarchical. like /about/history, /about/address, ... I don't know what the easiest way is for maintenance later, like whether i should make a controller w/o model for each static directory or use page controller and keep all files in views/pages/. any advice?
1

1 Answers

1
votes

If you don't mind having a .html extension on the end of your urls and have rewrite control over your server (mod_rewrite), you can add a rewrite rule that will directly serve your static content and totally bypass Cake. This could be the simplest for you, since all you have to do is create the static content somewhere under webroot/

For example, you could add the following for lighttpd (making sure that you have the mod_rewrite module loaded):

url.rewrite-once = (
    "^/.*\.html$"  => "$0"
)

Which translates to: take every request ending in .html (such as "/page.html" or "example/page.html") and serve it unmangled. The $0 is a keyword for the original request.

Or, for Apache (either in your config or in the app/webroot/.htaccess) make sure your rewrite rules start with these two, which say to serve any existing files or directories:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

Note that this rule has to come before your CakePHP rewrite rule in order to short-circuit it and serve the pages first, or else CakePHP routing will take over!