php - .htaccess 中的基本 URL

标签 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 等,或者我必须为我要加载的每个元素设置完整的 url 路径(CSS、图像、javascript、等等)?

谢谢

最佳答案

使用基本 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>

关于php - .htaccess 中的基本 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6848428/

相关文章:

PHP 自动完成功能不起作用

php - 如果项目数大于 4,Wordpress 将显示短代码

php - CakePhp 添加标签以选择 formhelper

html - 如何设置 <div> s inline : text, img, text, text

jquery - 固定表头,左列 x 和 y 滚动

apache - Letsencrypt 证书在 CentOS 6.8 32 位版本中不起作用

php - 将数组添加到sql数据库中

javascript - 使用 JavaScript 播放声音

php - Ubuntu 10.4 上的 APC 配置。 apc.shm_size、apc.shm_segments 和 Apache 的问题

python - Flask-reSTLess 与 mod_wsgi 无法连接到 MySQL 服务器