【发布时间】:2015-08-16 17:27:38
【问题描述】:
我正在尝试创建一个可以访问多级子文件夹的超链接结构。现在,我只能通过一级 (php) 目录访问我的超链接,例如 index.php?content=about(而 'about' 是 about.php)。
我想做的是为具有多级子目录的大型网站创建一个文件系统,如下例所示,
index.php?blog/category/process/。我不知道是否有一个符号可以替换 html 符号 / (目录的斜线)但是 PHP 目录。我尝试了不同的方式来访问多级子目录中的文件,例如将 ? (问号)。这一切都是假设性的实验。如果我使用斜杠,例如 '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”内的文档链接显示(之前是“404错误”,但标题和css文件不起作用。它们没有被拾取。
请注意:
我的网站结构是
标头(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找到了多级子目录结构的解决方案?也拾取了CSS,如下:
<a href="index.php?content=blog/category/process/filename">
(leave out the extension .php followed after 'filename')
感谢您的帮助!
【问题讨论】:
-
您使用什么服务器端技术?阿帕奇?
-
1.你能编辑 .htaccess 规则吗? .htaccess 中的实际重写规则是什么。
-
@eLearner
#RewriteCond %{HTTPS_HOST} ^mywebsite\.com$ [OR] #RewriteCond %{HTTPS_HOST} ^www\.mywebsite\.com$ #RewriteRule ^(.*) $ "https\:\/\/mywebsite\.com\/$1" [R=301,L]--- 我不介意在这里分享我的网站地址,但我不确定是否会违反规则。感谢您调查我的问题。