前端控制器的帮助
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
PHP
<?php
$pagesDir = "pages";
// Get the request
$page = $_SERVER['REQUEST_URI'];
// Strip the first slash
$page = substr($page, 1);
// Prevent access to higher level folders
$page = str_replace('..', '', $page);
// Do some mapping to actual files in a subfolder
$page = "$pagesDir/$page";
// Serve an error page if not found
if (!file_exists($page)) {
$page = "$pagesDir/error.html";
}
// Prevent anything from being output until it is ready
ob_start();
include($page);
$contents = ob_get_clean();
// Use a template with the variable $contents where you want the page's content to go
ob_start();
include($template);
$output = ob_get_clean();
echo $output;
?>
警告:include()[function.include]:无法在第29行的C: wamp www index.php中打开包含(include_path ='.; C: php5 pear')的''
$template
被评估为一个空字符串,而且我也没有看到它在PHP源代码中的任何地方声明。
上一篇: Frontcontroller help
下一篇: How to merge two SQL queries to get latest Wordpress Post and Featured Image