PHP url 函数和子域 [英] PHP url functions and subdomains

查看:33
本文介绍了PHP url 函数和子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站 thenoblesite.com.它有一些子域,即

I have a website thenoblesite.com. It has some subdomains i.e.

下载.thenoblesite.com
壁纸.thenoblesite.com

download.thenoblesite.com
wallpaper.thenoblesite.com
etc.

子域的页面存在于主 htdocs 文件夹中,即

Pages for subdomains are present in the main htdocs folder i.e.

httpdocs/download <- download.thenoblesite.com
httpdocs/wallpaper <- wallpaper.thenoblesite.com

httpdocs/download <- download.thenoblesite.com
httpdocs/wallpaper <- wallpaper.thenoblesite.com

问题是我正在使用 $_SERVER['DOCUMENT_ROOT'] .'/css'; 用于 css 文件夹和其他常用文件夹(图形、包含、脚本等).但是在子域页面 download.thenoblesite.com 中,$_SERVER['DOCUMENT_ROOT'] 将引用 download.thenoblesite.com 根文件夹,不是存在 css、graphics 和包含文件夹的主要 thenoblesite.com 根文件夹.

Problem is that I am using $_SERVER['DOCUMENT_ROOT'] . '/css'; for css folder and other common folders(graphics, includes, script etc). However in the subdomain page download.thenoblesite.com, $_SERVER['DOCUMENT_ROOT'] will refer to download.thenoblesite.com root folder, not the main thenoblesite.com root folder where css,graphics and includes folders are present.

我必须在所有子域上分别放置相同的图形、css 和包含文件夹.每次更新网站时,我都必须将公共文件夹复制到所有子域文件夹.

I have to place the same graphics, css and includes folders separately on all subdomains. Every time I update the website I have to copy the common folders to all subdomains folders.

另一个相关问题是,我必须对大型下载文件夹使用绝对链接,例如VLC 媒体播放器我必须使用 thenoblesite.com/download/vlc.exe 或者我还必须在所有子域文件夹中复制大型下载文件夹.这种方法不必要地增加了网站的大小,在我更新网站时造成混乱,并且看起来不太好编程.是否有任何可能的 PHP 解决方案,以便我可以为所有子域使用相同的 css、图像、下载和包含文件夹....

Another related problem is that i have to use absolute linking for the large sized downloads folder for e.g. VLC media player I have to use thenoblesite.com/download/vlc.exe or i also have to duplicate the large size download folder in all subdomain folders. This method unnecessarily increases the website size , creates confusion when I update the site and doesn't look good programming practise. Is there any possible PHP solution so that i can use the same css, images, downloads and includes folder for all subdomains....

推荐答案

我不确定这是否是您可能感兴趣的内容,但您始终可以创建一个新的子域并将其命名为 style.[domain] 和在您的配置文件中创建一个新变量并将其指向该变量.通过这种方式,您可以将所有图像和 css 文件等存储在一个地方,如果您的流量激增,您可以随时将该子域移动到 CDN 等,以便真正实现可定制化.

I am not sure if this is something you might be interested in, but you could always create a new subdomain and call it something like style.[domain] and create a new variable in your config file and point it to that. this way you have all the images and css files etc stored in one place and if your traffic spikes you can always move that subdomain to a CDN etc so its really customizable.

更新

好的,所以你可以简单地在你的配置文件中使用一个新变量,如下所示:

ok so you can simply use a new variable in your config file like below :

$_config['http'] = 'http://www.yousite.com/';

现在您可以使用此变量指向主站点上的所有下载等,而不是每个都指向子域的文件夹.如果你想更灵活,你还可以添加更多的 css 或 js 文件夹,如:

now you can just use this variable to point to all your downloads etc on the main site rather than each pointing to the subdomain's folder. and if you want to be more flexible you can also add a few more css or js folders like :

$_config['http'] = 'http://www.yousite.com/';
$_config['css'] = $_config['http']."css";
$_config['js'] = $_config['http']."js";

如果您决定四处移动文件或只是移动某个文件夹等,上述解决方案也会对您有所帮助.如果您可以采用它,这是一个很好的做法.

the solution above will also help you if you decided to move the files around or just move a certain folder around etc. this is a good practice if you can adopt it.

这篇关于PHP url 函数和子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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