[英]How do I set base URL for all pages of my website?
How do I set a base URL for my website and get it to include in every page? 如何为我的网站设置基本URL并将其包含在每个页面中?
Is there a way for me to easily change a variable to be the base url for the website, such as <?php $baseurl = "http://www.website.com/website/"; ?>
有没有办法让我轻松地将变量更改为网站的基本网址,例如
<?php $baseurl = "http://www.website.com/website/"; ?>
<?php $baseurl = "http://www.website.com/website/"; ?>
, and include this on every page so that all CSS, JavaScript, images and PHP includes follow this $baseurl
? <?php $baseurl = "http://www.website.com/website/"; ?>
,并将其包含在每个页面上,以便所有CSS,JavaScript,图像和PHP包含这个$baseurl
?
You can't make both PHP and client-side assets use the same base URL, unless you use PHP to echo
a base URL variable or constant to the page. 你不能让PHP和客户端资产使用相同的基本URL,除非你使用PHP来
echo
基本URL变量或常量的页面。
The usual approach is to have a bootstrap file that you include on every page, and define your base URL and other site-wide variables in there. 通常的方法是在每个页面上都包含一个引导程序文件,并在其中定义基本URL和其他站点范围的变量。
bootstrap.php: bootstrap.php中:
<?php
define('BASE_URL', 'http://example.com');
index.php: index.php文件:
<?php
include('bootstrap.php');
?>
<!DOCTYPE html>
<html>
<head>
<!-- // -->
<link rel="stylesheet" href="<?php echo BASE_URL; ?>/css/styles.css" />
</head>
<body>
<!-- // -->
</body>
</html>
You may want to take a look at the html base tag . 您可能想看看html基本标记 。
Inside the <head>
section of your html, put 在你的html的
<head>
部分里面,放
<base href="http://www.website.com/website/">
On top of that, you may want to have a base.php
with default directories and whatnot that you include into your project. 最重要的是,您可能希望拥有一个带有默认目录的
base.php
以及您在项目中包含的内容。
(xampp), the How do I use on the local computer. (xampp),我如何在本地计算机上使用。 folder layout,
文件夹布局,
http://www.resimagaci.com/img/90rvnrf.png http://www.resimagaci.com/img/90rvnrf.png
ust.php ust.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
</head>
<body>
alt.php alt.php
</body>
</html>
sabitler.php sabitler.php
<?php
#sabitler
define('BASE_URL', 'base-url');
?>
index.php 的index.php
<?php
include 'kutuphane/sabitler.php';
?>
<?php
$ust= BASE_URL . '/kutuphane/ust.php';
$alt= BASE_URL . '/kutuphane/alt.php';
?>
<?php
include ($ust);
?>
<?php
include ($alt);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.