How do I change the site root
I have used absolute links throughout my site, the problem comes when I am trying to set up a testing version in a subdirectory on another server. For example, the document structure is /images/image.jpg on the live server, but /subdirectory/images/im开发者_如何转开发age.jpg on the testing folder.
What is the solution? Cheers.
dirty and fast answer: use symlink
Move everything to /images/ and run this :
ln -s /images/ /subdirectory/images/
clean and slower answer: define a constant on a constant file. Use constants everywhere as a suffix to file location. Change the constant file for live
Best Answer: replicate environments (dev = live).
Don't use subfolders, use subdomains instead. Even on shared hosting you typically have the ability to set these up. It takes all of a few minutes, and you dont have to modify anything in your project.
Just do a var_dump($_SERVER) which is a array that stores a lot of server related variables. You will come up with something like
$_SERVER['SERVER_NAME'] $_SERVER['SERVER_PROTOCOL']
read http://php.net/manual/en/reserved.variables.server.php for a list of SERVER vars
精彩评论