.htaccess 中的基本 URL [英] Base URL in .htaccess

查看:19
本文介绍了.htaccess 中的基本 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I wonder if this is possible to tell via .htaccess or any other manners to set a base URL.

示例

我在 index.php 中的 CSS 是这样设置的

My CSS in the index.php is set like this

<link rel="stylesheet" href="css/style.css"/>

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

Everything works fine when i'm on the first directory to load my file and pages. But when I have a page set in a folder like /page/index.html. The css isn't loaded because the folder is not in page/ but in the root directory.

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

So is that possible to tell it to look always from the root directory to load the CSS, images, javascript, etc or I have to set the full url path to each element I want to load (CSS, images, javascript, etc)?

谢谢

推荐答案

使用 Base URL,例如:-

Use Base URL, for example:-

<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>

这篇关于.htaccess 中的基本 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆