如果我在登录页面 index.php 后键入任何参数,我的 CSS 样式将停止工作
我在运行 xampp 的本地开发服务器上添加/测试新代码,使用 php/javascript/html/css 编码。 编辑:我的开发服务器是 Windows Vista,我现在使用 Firefox 10.0.1 版。
今天我添加了 mod_rewrite 支持以允许为我的网站传递一个带有 URL 的参数 并偶然发现了一个我以前没想过要测试的问题。
我开发的mod_rewrite允许用户在站点名称后指定一个文本字符串,例如:
http://www.mysite.com/Stonehenge-artifact1
我的 mod_rewrite 处理该参数并做一些有意义的事情——具体来说,它从我的登录页面 index.php 重定向到一个完全不同的页面,该页面显示 Stonehenge-artifact1 的照片。
问题——如果用户键入 www.mysite.com/index.php/ialkselasdfa 我所有的 CSS 样式都消失了——我的 CSS 样式表中的 index.php 着陆页特殊字体和颜色都不见了。
我取消了所有 mod_rewrite 更改,包括完全删除 mysite.com 文件夹空间中的自定义 .htaccess 文件(使用 .htaccess 的本地自定义副本是 mod_rewrite 的步骤之一)。
我想看看 CSS 样式是否会消失,因为我回到了昨天的(mod_rewrite 更改之前的)代码。果然,如果我在 index.php 之后键入一个参数,任何参数,我的 CSS 样式表就会擅离职守。
因此以下 URL(例如)以某种方式禁用了我的 index.php CSS 样式表
www.mysite/index.php/foo
www.mysite/index.php/css-whereAreYou
(注意:我提出 mod_rewrite 的原因是为了解释为什么我首先要在网站 URL 的末尾输入一些内容。如果不是我测试新的 mod_rewrite 代码,我就不会发现这个问题。)
这是我在 CSS 样式表的 index.php 中包含的内容:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="globalStyles.css" />
</head>
我的 globalStyles.css 是:
root {
display: block;
}
body
{
color: black;
font-family: Gill, Helvetica, sans-serif;
font-size: 9pt;
background-color: RGB(243,239,240); /* light blue */
}
p
{
color: black;
}
为什么当我在 index.php 之后添加字符时,我的 index.php 登陆页面没有获得 CSS 样式?
最佳答案
您还可以使用 <base>
head 部分中的标记:
<base href="base/path/for/files/to/follow">
这样做是告诉浏览器指定的路径是根目录,应该请求相对于所述目录的相对路径。
我在 mod_rewrite
上遇到了同样的问题(不管你信不信,这个解决方案来自谷歌搜索,尽管我不得不深入挖掘)。
关于如果我在 index.php 之后输入一个参数,CSS 样式就会消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9272944/