簡體   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