有一个生成页面的脚本,以及一个 .htaccess 文件,它将对不存在页面的请求定向到所述脚本。例如:您的文件夹如下所示:
myfolder/
.htaccess
index.php
.ht 访问:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f #this rule skips the rewrite if the requested file actually exists
RewriteCond %{REQUEST_FILENAME} !-d #this rule skips the rewrite if the requested directory actually exists
RewriteRule ^(.*)$ index.php?req=$1 [L,QSA]
索引.php
<?php
if( !isset($_GET['req']) ) {
die("no page requested.");
// or whatever you want the default to be...
}
switch($_POST['req']) {
case 'dogs.html':
echo "dogs!";
break;
case 'cats.html':
echo "cats!";
break;
default:
echo "I don't know about that...";
}
因此您可以请求http://mysite.com/myfolder/cats.html
而无需实际将文件写入该目录。