繁体   English   中英

如何从URL中删除目录

[英]How to remove directory from the URL

我有这个文件结构:

    • 前端

      • 的index.php
    • 后端

    • 的index.php

如果可以,我可以将前端和后端文件夹隐藏为

localhost/new/frontend/index.php

会变成:

localhost/new/

我确信MVC将解决您当前的问题。 因此,我们应该遵循MVC标准来建立网站。

一些例子:

https://medium.com/@noufel.gouirhate/create-your-own-mvc-framework-in-php-af7bd1f0ca19

https://github.com/DawidYerginyan/simple-php-mvc

如果使用本机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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM