Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

php - Base URL in .htaccess

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

Example

My CSS in the index.php is set like this

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

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.

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

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...