我不知道到底是什么问题,但我已经对 PHP 中的斜杠进行了大量研究。
我的问题是,当我访问我的网站时,我总是看到斜杠,这会导致所有资源无法加载。
如何禁用添加到.htaccess
. 谢谢!
默认情况下,PHP 不会将 / 添加到 URL,这是您的脚本执行的操作。
如果您想使用 style.css 无论如何,请使用绝对路径或完整路径 - 所以如果您的 style.css 是 on http://domain.com/style.css
,那么您可以使用
<link rel="stylesheet" type="text/css" href="/style.css">
或者
<link rel="stylesheet" type="text/css" href="http://domain.com/style.css">
使用您的 file.php 东西,它会在 . 中查找http://domain.com/file.php/style.css
,而上述任何一个都使用您在http://domain.com/style.css
.
这也适用于http://domain.com/folder/file.php
- 只需/folder/style.css
在href
-tag 中使用,或者再次使用它的完整 URL。
URL 中的 / 表示网络服务器文件系统上的目录,因此您的请求file.php/
是查找目录而不是 PHP 脚本文件。
可以在重写指南中找到 htaccess 重写,以便任何目录自动附加斜杠:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [R]
只需使用 css 文件的完整路径,例如。
<link rel="stylesheet" type="text/css" href="http://yourdomain/folder/file.css"/>