.htaccess 创建后的文件路径
Filepathes after .htaccess creation
我在创建受 .htaccess 保护的 admin 目录后遇到 filepath 问题。
这是文件夹的结构:
file-controller4.php 最初位于 file-[ 旁边目录的 root =72=] 和 file-view4.php 位于 view 目录中。
要从 file-controller4.php 调用 header.php 我使用 set_include_path。
问题是 header 不再调用 css 文件,这似乎与管理目录。
以下是不同的文件:
管理文件夹:
文件-controller4.php
<?php
set_include_path ( 'E:/xampp/htdocs/url/' );
include '/view/header.php';
include '/admin/file-view4.php';
文件-view4.php
<h1>This is a title</h1>
根文件夹:
文件-controller3.php
<?php
include '/view/header.php';
include '/view/file-view3.php';
查看文件夹:
文件-view3.php
<h1>This is a title</h1>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<!--<meta charset="utf-8"></meta>-->
<meta http-equiv="Content-Type" content="text/html;" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<title>A TEST</title>
<link rel="stylesheet" type="text/css" href="css/css-example.css" ></link>
</head>
css文件夹:
css-example.css
html, body {
margin: 0;
padding: 0;
}
body {
background-color: white;
font-family: Verdana, sans-serif;
font-size: 100%;
}
h1 {
font-size: 200%;
color: navy;
text-align: center;
}
我如何从 file-controller4 加载 CSS 就像它对 file-controller3 正确加载一样?
感谢您的帮助。
您可以签入 header.php REQUEST_URI 并检测脚本在哪里 - 在主文件夹或管理员中。然后为 CSS.
构建 url
喜欢
<?php
if (strpos($_SERVER["REQUEST_URI"], "admin") !== false) {
$css_prefix = "../";
} else {
$css_prefix = "";
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo($css_prefix); ?>css/css-example.css" ></link>
但最好和正确的方法是更改应用程序的逻辑并将 file-controller3.php
移动到文件夹 admin
中
我在创建受 .htaccess 保护的 admin 目录后遇到 filepath 问题。
这是文件夹的结构:
file-controller4.php 最初位于 file-[ 旁边目录的 root =72=] 和 file-view4.php 位于 view 目录中。 要从 file-controller4.php 调用 header.php 我使用 set_include_path。
问题是 header 不再调用 css 文件,这似乎与管理目录。
以下是不同的文件:
管理文件夹: 文件-controller4.php
<?php
set_include_path ( 'E:/xampp/htdocs/url/' );
include '/view/header.php';
include '/admin/file-view4.php';
文件-view4.php
<h1>This is a title</h1>
根文件夹:
文件-controller3.php
<?php
include '/view/header.php';
include '/view/file-view3.php';
查看文件夹:
文件-view3.php
<h1>This is a title</h1>
header.php
<!DOCTYPE html>
<html lang="en">
<head>
<!--<meta charset="utf-8"></meta>-->
<meta http-equiv="Content-Type" content="text/html;" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<title>A TEST</title>
<link rel="stylesheet" type="text/css" href="css/css-example.css" ></link>
</head>
css文件夹:
css-example.css
html, body {
margin: 0;
padding: 0;
}
body {
background-color: white;
font-family: Verdana, sans-serif;
font-size: 100%;
}
h1 {
font-size: 200%;
color: navy;
text-align: center;
}
我如何从 file-controller4 加载 CSS 就像它对 file-controller3 正确加载一样?
感谢您的帮助。
您可以签入 header.php REQUEST_URI 并检测脚本在哪里 - 在主文件夹或管理员中。然后为 CSS.
构建 url喜欢
<?php
if (strpos($_SERVER["REQUEST_URI"], "admin") !== false) {
$css_prefix = "../";
} else {
$css_prefix = "";
}
?>
<link rel="stylesheet" type="text/css" href="<?php echo($css_prefix); ?>css/css-example.css" ></link>
但最好和正确的方法是更改应用程序的逻辑并将 file-controller3.php
移动到文件夹 admin