【发布时间】:2019-04-06 06:51:16
【问题描述】:
我有这个文件结构:
-
新的
-
前端
- index.php
后端
- index.php
-
如果可以,我可以让前端和后端文件夹隐藏起来
localhost/new/frontend/index.php
将变成:
localhost/new/
【问题讨论】:
标签: php apache .htaccess url mod-rewrite
我有这个文件结构:
新的
前端
后端
如果可以,我可以让前端和后端文件夹隐藏起来
localhost/new/frontend/index.php
将变成:
localhost/new/
【问题讨论】:
标签: php apache .htaccess url mod-rewrite
我确信 MVC 将解决您当前的问题。所以,我们应该按照MVC标准来实现网站。
一些例子:
https://medium.com/@noufel.gouirhate/create-your-own-mvc-framework-in-php-af7bd1f0ca19
【讨论】:
如果您使用原生 PHP 编写它,那么您必须编写自己的路由系统。像这样的:
$str = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$sections = explode("/", $str, 3);
$page = (isset($sections[2]) && $sections[2] != '') ? $sections[2] : 'homepage';
$page = parse_url($page);
$page = trim($page['path'], '/');
// list of your custom php function
$functions = array(
'contact-us-success' => 'contact_us_success',
);
//check functions first
if (isset($functions[$page]))
{
call_user_func($functions[$page]);
return true;
}
//else check page
elseif (is_file("pages/{$page}.php"))
{
include_once("pages/template/header.php");
include_once("pages/{$page}.php");
include_once("pages/template/footer.php");
return true;
}
【讨论】: