我想为我正在处理的网站设置自定义模板系统,因此我想将所有请求重定向到单个文件。如果用户访问http://www.mywebsite.de/products/software/
之类的网址,我想将其请求重定向到index.php
这样的文件,那么我可以执行以下操作:
$look_at = $_GET['first_level']; //for example: products
if($look_at == 'products') {
$look_at = $_GET['second_level']; //here: software
if($look_at == 'software') {
//show software specific stuff
} else if ($look_at == 'hardware') {
//show hardware specicif stuff
} else {
//show error message
}
} else {
//show error message
}
然后,我可以include
将其他html文件用于index.php
,具体取决于所请求的内容。
最后,http://www.mywebsite.de/products/software/
之类的请求应该与http://www.mywebsite.de/index.php?first_level=products&second_level=software
答案 0 :(得分:1)
RewriteEngine on
RedirectMatch 403 /\..*$
# If the directory or file exists, use them directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise, send a request to the index.php file
RewriteRule . index.php
下一步在PHP示例中:
$URI = $_SERVER['REQUEST_URI'];
if (($qpos=(strpos($URI,'/?')))!==false)
$URI=substr($URI,0,++$qpos);
elseif (($qpos=(strpos($URI,'?')))!==false)
$URI=substr($URI,0,++$qpos);
$URI = (preg_replace('/^\/|\/$/', '',$URI));