首页 > 解决方案 > 如何在php中控制相对路径

问题描述

在我的项目中,href 有问题。

我的html页面是a.php,它的代码是:

<!doctype html>
<html lang="en">
 <head>
 <meta charset="utf-8" />
  <link rel="shortcut icon" href="favicon.ico" />
  <link rel="stylesheet" type="text/css" href="http://www.ulpin.com /css/bootstrap.min.css">
  <style>
  dd{word-wrap:break-word;};
  </style>
  <title>SystemTitle</title>
  <script type="text/javascript" src="static/js/jquery-1.7.2-min.js">  </script>
  <script type="text/javascript" src="static/js/bootstrap.min.js"></script>
    <base target="_self"/>
 </head>
 <body>
  <br/>
  <br/>
  <br/>
  <br/>
 <div class="container">
<center>
    <a href="active.php" class="btn">ManTest</a><br/><br/>
</center>
</div>
   </body>
 </html>

但它工作失败。于是我用firefox查看了页面源代码,当我点击static/js/jquery-1.7.2-min.js的href时,它显示:

Not Found

The requested URL /o1ws1v/web/admin/static/js/jquery-1.7.2-min.js was not found on this server. 

src 已更改。“/o1ws1v/web/admin/”是自动添加的。

为什么?

我的折叠结构是:

 /yjdata/www/www/o1ws1v/web/admin/a.php
 /yjdata/www/www/o1ws1v/web/static/js/jquery-1.7.2-min.js
 /yjdata/www/www/o1ws1v/web/static/js/bootstrap.min.js

否则,a.php 放在 /yjdata/www/www/o1ws1v/web/ 中,它工作正常

谁能帮我?

标签: phphtmlpath

解决方案


这是一个简单的路径问题。

当您处于/yjdata/www/www/o1ws1v/web/admin/a.php使用src="static/js/jquery-1.7.2-min.js"状态时,会发生这种情况:

--/yjdata/www/www/o1ws1v/web/admin/
                         |     |--- a.php    <-- You are here
                         |     |--- static/  <-- This is where the browser think that the static folder exists 
                         |--- static/        <-- This is where the folder really is !

因此,您需要a.php在 src 路径中上一层楼:

<script type="text/javascript" src="../static/js/jquery-1.7.2-min.js">  </script>

..指示父目录。


推荐阅读