首先.htaccess
,我发送url
到public/index.php
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ public/index.php [NC,L]
我的public/index.php
:
<?php
// define root path of the site
if(!defined('ROOT_PATH')){
define('ROOT_PATH','../');
}
require_once ROOT_PATH.'function/my_autoloader.php';
use application\controllers as controllers;
$uri=strtolower($_SERVER['REQUEST_URI']);
$actionName='';
$uriData=array();
$uriData=preg_split('/[\/\\\]/',$uri );
$actionName = (!empty($uriData[3])) ? preg_split('/[?].*/', $uriData[3] ): '' ;
$actionName =$actionName[0];
$controllerName = (!empty($uriData[2])) ? $uriData[2] : '' ;
switch ($controllerName) {
case 'manage':
$controller = new Controllers\manageController($controllerName,$actionName);
break;
default:
die('ERROR WE DON\'T HAVE THIS ACTION!');
exit;
break;
}
// function dispatch send url to controller layer
$controller->dispatch();
?>
我有这个目录:
- 应用
- 控制器
- 楷模
- 看法
- 上市
css
java script
- 索引.php
.htaccess
URL
例如,我想要干净localhost/lib/manage/id/1
而不是localhost/lib/manage?id=1
,我应该怎么做?