Jump to content

Recommended Posts

I'm a freelance web designer and I've begun to use PHP extensively for my clients' websites. A problem I run into is the consistent use of "/" for the site root. My server thinks that that refers to public_html/, meaning I can't test a site with "/" used to recognize the site root if I'm, say, one directory deep. How can I have a specific website recognize its own base folder as the site root? I imagine that in PHP, without touching Apache config files, there's a way to set a new site root, I just don't know how. :( :( :(

Link to comment
https://forums.phpfreaks.com/topic/71742-site-root/
Share on other sites

Yes, it does. But imagine:

(1) I have my portfolio website. This is the only one where a URL like "/images/logo.png" would work, because I store this site in the public_html folder, which my server has set as the root.

 

(2) I have many websites for clients. When I deploy on their server, "/images/logo.png" will work fine for their site, but right now I have it located on my server at "/clientA/images/logo.png". However, for the Header include, I'd like to have <img src="/images/logo.png" />. If I do that, it will point to my website's logo, and not theirs.

 

(3) I'd like their site root to be located not at public_html/, but at public_html/clientA/ so that I can easily deploy/migrate.

Link to comment
https://forums.phpfreaks.com/topic/71742-site-root/#findComment-361293
Share on other sites

A site within a site is just that. They share the same document root because they are actually the same site.

 

Ive always used a seperate vhost when developing for clients.

 

One thing you could probably do would be to create your own $root var. eg;

 

$root = $_SERVER['DOCUMENT_ROOT'] . '/clientA';

 

However then you'll need to include this variable anywhere you need to use it. Also, it will not effect pure html such as <img src='/images/logo.png'>. You would need to use <img src='<?php echo $root ; ?>/images/logo.png'>

Link to comment
https://forums.phpfreaks.com/topic/71742-site-root/#findComment-361298
Share on other sites

Which is really no better than adding "/clientA" to every absolute root URL and using a site-wide Replace to wipe it out later. I wish there were another way, and it defies reason that PHP doesn't provide a way to set a non-global site root for a specific script or set of scripts.

Link to comment
https://forums.phpfreaks.com/topic/71742-site-root/#findComment-361319
Share on other sites

The "/" indicating the site root is completely up to PHP.

 

Are you talking about this?

 

<img src="/images/logo.png" />

 

/ is not the document root defined by php, that is your server (and that code is not php). If you use php to attempt to include a file like so...

 

include '/foo/bar/';

 

php will search for bar in the root of your filesystem, not your web doc root.

Link to comment
https://forums.phpfreaks.com/topic/71742-site-root/#findComment-361429
Share on other sites

Which is really no better than adding "/clientA" to every absolute root URL and using a site-wide Replace to wipe it out later. I wish there were another way, and it defies reason that PHP doesn't provide a way to set a non-global site root for a specific script or set of scripts.

 

A non global site root?  By that do you mean set a variable to something like '/clientA/' because if that's what you mean, that's what thorpe suggested....

 

I get a little crazy with the use of vhosts.... I have around 15 (most of them are just entries in my hosts file ;p).

Link to comment
https://forums.phpfreaks.com/topic/71742-site-root/#findComment-361442
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.