views:

14

answers:

1

I'm working on a simple website. I'm using a template file (template.php), which has all the shared HTML, and accepts a parameter (say 'page'). then opens the page file and includes the page in itself. something like this: (the code is just a prototype. no validation/filtering is required).

<?php
//template.php
?>
<html>
    <body>
      <div>my web site</div> <!-- shared by all pages -->
      <div> <!-- specific page contents -->
         <?php include($_REQUEST['page']); ?>
      </div>
    </body>
</html>

what the .htaccess file should be like, so the request for PHP files, goes through the template.php file with the 'page' parameter as the name of the requested file name?

A: 

Try this rule:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ template.php?page=$0 [L]

The additional RewriteCond conditions are to exclude requests that can be mapped to existing files (-f) or directories (-d).

Gumbo
Thanks but I'm not sure about this, because:1. I need this rule to be applied on only .php files2. my .php files already exist (because I am including them).
farzad