有一個生成頁面的腳本和一個將不存在頁面的請求引導到所述腳本的.htaccess文件。例如:您的文件夾看起來像:
myfolder/
.htaccess
index.php
的.htaccess:
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]
的index.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
而無需實際寫入一個文件到目錄。
如果你並不需要保存的頁面,你爲什麼要試圖寫的目錄?爲什麼不把HTML輸出到瀏覽器? – Axel
你爲什麼每次都生成一個文件?爲什麼不通過PHP將類添加到html標籤中,並使用CSS來更改顏色? – dudewad