php - 在php中链接资源
问题描述
我的应用程序具有以下文件结构
/App
/html
404.html
another.html
other.html
/css
main.css
.htaccess
index.php
我正在从with发送other.html
文件。index.html
readfile()
所有 html 文件共享
main.css
.
index.html
看起来像这样
<html>
<head>
<link rel="stylesheet" href="../css/main.css">
</head>
<body>
<a href="another.html">link</a>
</body>
</html>
我在 XAMPP 上运行它。和
http://localhost/App
我能够检索 index.html,但是当我点击我得到的链接时404.html
,正如我所写的那样another.html
,../css/main.css
服务器正在寻找http://localhost/App/another.html
和http://localhost/css/main.css
。这会导致 404.html 和 index.html 中的 CSS 混乱
我尝试通过替换来解决这个问题../css/main.css
,css/main.css
但是每当遇到错误时,这都会导致 404.html 中的 CSS 混乱。我尝试的另一个尝试是/css/main.css
,但再次没有运气服务器正在寻找http://localhost/css/main.css
。
那么,如何链接这些文件?是否有任何可用的配置.htacccess
可以说 server to look /
(root) as /App
,所以如果有任何配置,那么我可以通过说/css/main.css
,/html/another.html
等等来让一切正常工作?或者有什么其他建议?
这是问题的视频:https ://youtu.be/Qg7K8gOdyW0
解决方案
将以下代码放入您的 .htaccess 文件中:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/App/
RewriteRule ^(.*)$ /App/$1 [L,R=301]
在 index.html 中使用下一个链接:
/html/another.html
/css/main.css
推荐阅读
- javascript - 如何调整这个固定的表格标题,使其左对齐而不是居中?
- sql-server-2008 - 在新连接的数据库 SQL Server 2008 上启用用户登录
- node.js - 使用 SinonJS,UnhandledPromiseRejectionWarning 捕获抛出的错误
- php - $route.query.page 返回错误的值或者是 v-if 条件下的类型转换问题
- c# - 使用 Microsoft Bot SDK 使机器人转发活动
- excel - 仅当特定单元格值更改时才执行宏
- c - 在 C 中打印 UTF-8 字符串的字节
- javascript - MVC5 Uncaught ReferenceError:addNewRowTract 未在 HTMLButtonElement.onclick 中定义
- psychopy - PsychoPy - 对比敏感度测量 - Pokorny&Smith 基座任务
- visual-studio-2017 - Visual Studio SSRS 2016 - 在环境变化时切换数据源