Re: [SMARTY] Configuring apache to fallback to a default template handler
| From: | Mark Gibson | Date: | Tue, 06 Apr 2004 10:00:53 +0000 |
| Subject: | Re: [SMARTY] Configuring apache to fallback to a default template handler | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-11233@lists.php.net to get a copy of this message | ||
Mark Gibson wrote:
I have the following PHP/Smarty project structure: myapp/Sorry, made a mistake here, should be: template/htdocs/ - public access document root default.php - default template handler ...other php scripts...templates/ - smarty templates about/ company.html
page/
about/
company.html
To keep page templates separate from others.
Given a URL, eg: http://www.things-n-stuff.com/about/company I want to check for files in the following order: 1, htdocs/*.php - if this exists then handle with mod_php, as normal (eg. htdocs/about/company.php) 2, templates/*.html - if this exists then passthru to htdocs/default.php (eg. templates/about/company.html) 3, otherwise, perform a normal 404 error via Apache. Thanks to Scott and Mark for your feedback.After revisiting the mod_rewrite docs and some experimenting, i've come up with the following. In the htdocs/.htaccess file: RewriteEngine On # If the requested file doesn't exist in htdocs ...
RewriteCond %{REQUEST_FILENAME} !-f
# ... and, a page template with the requested filename exists ...
# (note: APP_ROOT is set by my virtual host rewrite rules)
RewriteCond %{ENV:APP_ROOT}template/page/$1.html -f
# ... then, set the TEMPLATE var to the template name and
# pass to the index.php script.
RewriteRule ^(.+) /default.php [L,E=TEMPLATE:page/$1.html]Then within the default.php script, the template name can be retreived from $_SERVER['REDIRECT_TEMPLATE']. This works only if you don't use extensions in the URL's (ie leave off the .php/.html) and doesn't work well with URL's ending with /. Hope someone finds this useful. Ideas and improvements welcome :) -- Mark Gibson <gibsonm |AT| cromwell |DOT| co |DOT| uk> Web Developer & Database Admin Cromwell Tools Ltd. Leicester, England.