简体   繁体   中英

How to remove directory from the URL

I have this file structure:

  • New

    • frontend

      • index.php
    • backend

    • 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. So, we should implement the website by following the MVC standard.

Some examples:

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

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

If you're writing it in native PHP then you have to write your own routing system. 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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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