通过 index.php 超链接 multi-level sub-directories?结构体

Hyperlink multi-level sub-directories through index.php? structure

我正在尝试创建一个可以访问 multi-level 子文件夹的 hyperlink 结构。现在,我只能通过 one-level (php) 目录访问我的 hyperlinks,例如 index.php?content=about(而 'about' 是 about.php ).

我想做的是用 multi-level sub-directories 为更大的网站创建一个文件系统,如下例所示, index.php?blog/category/process/。我不知道是否有一个符号可以代替 html 符号 /(目录的斜杠)但用于 PHP 目录。我尝试了不同的方式来访问 multi-level sub-directories 中的文件,例如将 ? (问号)。这都是假设性的实验。如果我使用斜杠,例如“blog/category/process/filename.php”的形式,我会收到 404 Not Found 错误。

function.php里面有下面的PHP脚本,它从URL中获取内容,如果没有内容,它设置一个默认值,如果有内容,它清理数据以防止黑客攻击:

function loadContent($where, $default='') {
$content = filter_input(INPUT_GET, $where, FILTER_SANITIZE_STRING);
$default = filter_var($default, FILTER_SANITIZE_STRING);
$content = (empty($content)) ? $default : $content;

if ($content) {
$html = include 'content/'.$content.'.php';
return $html;
  }
}

function loadIncludes($where, $default='includes/') {

$includes = filter_input(INPUT_GET, $where, FILTER_SANITIZE_STRING);
$default = filter_var($default, FILTER_SANITIZE_STRING);

if($includes) {

$html = include 'includes/'.$includes.'.php';
    return $html;
  }
}

显示 'blog/category/process/filename.php' 中文档的 link(之前是“404 错误”,但 header 和 css 文件不起作用.他们没有被捡到。

请注意:
我的网站结构是
Header(一个 header 被 index.php 捡到?)
内容(多个内容=filename.php)
页脚

index.php 看起来像这样:

<?php   
require ('includes/function.php');
require ('includes/init.php');  /* init.php picks up the header */
?>

<div class="clearboth"></div>

<!-- ********  HOMEPAGE  **********  -->
<?php loadContent('content', 'home'); ?>

<div class="clearboth"></div>

<!-- ********  FOOTER  **********  -->  
<?php include ('content/footer.php');  ?>

我通过index.php在multi-levelsub-directories的结构上找到了解决方案?也拿起 CSS,如下所示:

<a href="index.php?content=blog/category/process/filename">
(leave out the extension .php followed after 'filename')

感谢您的帮助!

<?php
/* FOLDERS STRUCTURE

$_SERVER['DOCUMENT_ROOT'] = C:/Server/www/music; // YES Windows :)
THIS FILE = folders.php

C:/Server/www/music
C:/Server/www/music/files/
C:/Server/www/music/files/folder1/
C:/Server/www/music/files/folder1/folder2/myfile.jpeg

*/

$root = $_SERVER['DOCUMENT_ROOT'];
$requestURI = $_SERVER['REQUEST_URI'];
$startFolder = '/files/';
preg_match('/\?/', $requestURI) ? list($requestURI, $fileToFind) = explode('?', $_SERVER['REQUEST_URI']) : exit('Bad request'); 
$file = $root.$startFolder.$fileToFind;    

if(file_exists($file)){

    //YOUR CODE 
}
else {

    header("HTTP/1.0 404 Not Found");

}

// Usage = http://music.com/folders.php?/folder1/folder2/myfile.jpeg
?>

阅读我之前提出的那些问题。希望对你有所帮助

.htaccess : Redirect all http requests to one file whitout 404 resp. code

Use PHP to rewrite URLS?

请注意,您可以使用 http headers header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");header($_SERVER["SERVER_PROTOCOL"]." 200 Ok"); 以防文件存在或不存在

发挥你的想象力...

我通过index.php找到了多级子目录超链接结构的解决方法?也拾取 CSS,并且不会发出 404 错误,如下所示:

<a href="index.php?content=blog/category/process/filename">
descriptive header
</a>

(注意:记得在 'filename' 之后省略扩展名 .php)