在URL末尾添加斜杠时CSS消失 [英] CSS dissapears when adding trailing slash to URL
问题描述
问题在于,当我在地址栏网址localhost/register.php/
处添加斜杠时,CSS消失了(不再适用). CSS位于单独目录中的单独文件中.结构如下:
The problem is that when I add a trailing slash at the address bar url localhost/register.php/
the CSS dissapears (is not applied anymore). CSS is in a separate file in a separate dir. Here is the structure:
CSS
header.html
包含在index.php
和include 'includes/header.html';
在Windows 7下运行apache.
Running apache under Windows 7.
推荐答案
添加斜杠后,浏览器会假定register.php
是另一个目录,而不是文件.当指定了相对URL时,将相对于子目录register.php/
(由于斜杠)来寻找外部资源.
When a trailing slash is added, your browser assumes register.php
to be another directory, rather than a file. When relative URLs are specified, the external resource will be sought relative to the subdirectory register.php/
(because of the slash).
示例:
- 在添加斜杠之前:
css/style.css
>http://localhost/css/style.css
- 添加斜杠后:
css/style.css
>http://localhost/register.php/css/style.css
.
- Before adding a slash:
css/style.css
>http://localhost/css/style.css
- After adding a slash:
css/style.css
>http://localhost/register.php/css/style.css
.
修复
要解决此问题,请使用绝对URL.以下任一项:
Fixing
To fix this issue, make use of absolute URLs. Either of the following:
-
<link href="/css/style.css" ... />
-
<link href="http://localhost/css/style.css" ... />
-
<base href="/register.php" />
(此标记必须在<head>
中指定
<link href="/css/style.css" ... />
<link href="http://localhost/css/style.css" ... />
<base href="/register.php" />
(this tag has to be specified within the<head>
这篇关于在URL末尾添加斜杠时CSS消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!