简体   繁体   English

如何从URL中删除目录

[英]How to remove directory from the URL

I have this file structure: 我有这个文件结构:

  • New

    • frontend 前端

      • index.php 的index.php
    • backend 后端

    • index.php 的index.php

If Can can I make frontend and backend folder hide like 如果可以,我可以将前端和后端文件夹隐藏为

localhost/new/frontend/index.php

Will become: 会变成:

localhost/new/

I'm sure that MVC will resolve your current issue. 我确信MVC将解决您当前的问题。 So, we should implement the website by following the MVC standard. 因此,我们应该遵循MVC标准来建立网站。

Some examples: 一些例子:

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

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

If you're writing it in native PHP then you have to write your own routing system. 如果使用本机PHP编写,则必须编写自己的路由系统。 Something like this: 像这样:

$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