Php .htaccess中的基本URL
我想知道是否可以通过.htaccess或任何其他方式来设置基本URL 范例 index.php中的CSS设置如下Php .htaccess中的基本URL,php,html,apache,.htaccess,url-rewriting,Php,Html,Apache,.htaccess,Url Rewriting,我想知道是否可以通过.htaccess或任何其他方式来设置基本URL 范例 index.php中的CSS设置如下 <link rel="stylesheet" href="css/style.css"/> 当我在第一个目录上加载文件和页面时,一切正常。但是当我在/page/index.html这样的文件夹中设置页面时。未加载css,因为文件夹不在page/中,而是在根目录中 那么,是否可以告诉它总是从根目录查看以加载CSS、图像、javascript等,或者我必须为要加载的每个
<link rel="stylesheet" href="css/style.css"/>
当我在第一个目录上加载文件和页面时,一切正常。但是当我在/page/index.html这样的文件夹中设置页面时。未加载css,因为文件夹不在page/中,而是在根目录中
那么,是否可以告诉它总是从根目录查看以加载CSS、图像、javascript等,或者我必须为要加载的每个元素(CSS、图像、javascript等)设置完整的url路径
谢谢您应该在页面中使用绝对路径:
<link rel="stylesheet" href="/css/style.css"/>
基本标记可能会引起许多麻烦,因为所有非绝对URI都将与它一起使用。您可能要查找的是HTML
标记。它是文档的基本URI,所有相关链接都解析为。如果标记不在文档源中,则将使用浏览器地址中的URI
除此之外,您还可以使用绝对URI
请参阅了解您正在使用的内容。您正在查找html标记。引用文件: 例如,给定以下基本声明和声明:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML>
<HEAD>
<TITLE>Our Products</TITLE>
<BASE href="http://www.aviary.com/products/intro.html">
</HEAD>
<BODY>
<P>Have you seen our
<A href="../cages/birds.gif">Bird Cages</A>?
</BODY>
</HTML>
我们的产品
你看过我们的电影了吗
?
相对URI“./cages/birds.gif”
将决心:
使用基本URL,例如:-
<html>
<head>
<base href="http://www.w3fools.com/" target="_blank" />
<!-- only one base element is allowed -->
<link rel="stylesheet" type="text/css" href="/stdtheme.css" />
</head>
<body>
<img src="stickman.gif" width="24" height="39" /> - Notice that we have only specified a relative address for the image. Since we have specified a base URL in the head section, the browser will look for the image at "http://www.w3schools.com/images/stickman.gif"
<br /><br />
<a href="http://www.w3fools.com">Don't use W3Schools</a> - Notice that the link opens in a new window, even if it has no target="_blank" attribute. This is because the target attribute of the base element is set to "_blank".
</body>
</html>
-请注意,我们只为图像指定了一个相对地址。由于我们在head部分中指定了一个基本URL,浏览器将在“”处查找图像http://www.w3schools.com/images/stickman.gif"
-请注意,链接将在新窗口中打开,即使它没有target=“\u blank”属性。这是因为基本元素的目标属性设置为“\u blank”。
该死的,为什么我没有在我面前搜索正确的东西,而不是在里面搜索更复杂的方法。htaccess:P。Thanks@Warface我建议您使用php解析url。如果你对基本标签满意,我也一样happy@pornel谢谢你的改变