.htaccess中的基本URL

War*_*ace 4 html php apache .htaccess url-rewriting

我想知道是否可以通过.htaccess或任何其他方式来设置基本URL.

我在index.php中的CSS设置如下

<link rel="stylesheet" href="css/style.css"/>
Run Code Online (Sandbox Code Playgroud)

当我在第一个目录加载我的文件和页面时,一切正常.但是当我在/page/index.html这样的文件夹中设置页面时.未加载css,因为该文件夹不在页面/但在根目录中.

那么可以告诉它总是从根目录看加载CSS,图像,javascript等,或者我必须设置我想要加载的每个元素的完整url路径(CSS,图像,javascript等)?

谢谢

Nag*_*h M 6

使用基本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>
Run Code Online (Sandbox Code Playgroud)