简体   繁体   English

如何告诉子域的索引调用子目录的index.php文件中根目录的全部内容?

[英]How do I tell the index of my subdomain to call the entire contents of the root directory in the index.php file of my sub-directory?

I am fairly new to php but I have an index file in my root directory where I define some php variables and call the "header.php" file which contains my site content. 我对php还是很陌生,但是我在根目录中有一个索引文件,在其中定义了一些php变量并调用了包含我的网站内容的“ header.php”文件。

Here is the structure. 这是结构。

I have two domains 我有两个域

mysite.com -> references the root folder, the index file (which contains my dynamic variables) calls header.php using php includes which loads images, css, and content mysite.com- >引用根文件夹,索引文件(包含我的动态变量)使用php调用header.php,其中包括加载图像,css和内容

domain1.mysite.com -> references a sub-directory titled "domain1". domain1.mysite.com- >引用一个名为“ domain1”的子目录。 In domain1 I have an index file with seperately defined variables and I would like to call the SAME header and content that mysite is calling in the root directory. 在domain1中,我有一个带有单独定义的变量的索引文件,我想在根目录中调用SAME标头和mysite正在调用的内容。 However, because I am calling it from a sub-directory, it does not load images or CSS. 但是,因为我是从子目录中调用它的,所以它不会加载图像或CSS。

I think this is a simple fix, but how do I tell the index of my subdomain to call the entire contents of the root directory in the index.php file of my sub-directory? 我认为这是一个简单的修复程序,但是如何告诉子域的索引调用子目录的index.php文件中根目录的全部内容?

Try using absolute paths in your header.php file, so rather than: 尝试在header.php文件中使用绝对路径,而不是:

<link src="../path/to/file.css" />

<link src="/root/path/to/file.css" />

You actually won't be able to do it directly the way you are trying because the CSS is above the "top" of the website. 实际上,您将无法以尝试的方式直接执行此操作,因为CSS位于网站“顶部”上方。 You do have a couple of solutions, however. 但是,您确实有几个解决方案。

1) You can edit your HTML code to reference the main domain, such as: 1)您可以编辑HTML代码以引用主域,例如:

2) You can copy the CSS to the domain1.mysite.com directory 2)您可以将CSS复制到domain1.mysite.com目录

3) If you plan to change your CSS often, you can avoid having to maintain two directories with the same CSS by creating a "symbolic link" on your server so that it looks like there are two directories, but they are really just one. 3)如果您计划经常更改CSS,则可以通过在服务器上创建“符号链接”来避免看起来必须维护两个具有相同CSS的目录,这样看起来好像有两个目录,但实际上它们只是一个。 You will also need to make sure that your web server (probably Apache) has permission to follow links. 您还需要确保您的Web服务器(可能是Apache)有权访问链接。 Your server administrator can help you will all of this. 您的服务器管理员可以帮助您完成所有这一切。

4) Depending on the software available on your server, you might also be able to use a PHP script to grab the file. 4)根据服务器上可用的软件,您也许还可以使用PHP脚本来获取文件。 For example, in your domain1.mysite.com folder, create a PHP script such as: 例如,在您的domain1.mysite.com文件夹中,创建一个PHP脚本,例如:

<?php
header("Content-type: text/css;");
include("../style.css");
?>

Don't worry if you script file ends in .php instead of .css. 不用担心脚本文件以.php而不是.css结尾。 The header will tell the browser that it is a CSS file. 标头将告诉浏览器它是一个CSS文件。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM