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 -开发者_如何学C->
<?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?
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
).
精彩评论