[英]Change PHP $_SERVER['DOCUMENT_ROOT'] with htaccess only in sub folder, and leave the it without change in the root directory
I have 2 websites. 我有2个网站。 One is in the /public_html
and the second in sub folder /public_html/site2
. 一个在/public_html
,第二个在子文件夹/public_html/site2
。
I want to change the $_SERVER['DOCUMENT_ROOT']
in the /site2
directory so its $_SERVER['DOCUMENT_ROOT']
will start from /public_html/site2
instead of public_html
. 我想更改/site2
目录中的$_SERVER['DOCUMENT_ROOT']
,以便其$_SERVER['DOCUMENT_ROOT']
从/public_html/site2
而不是public_html
。 BUT the first site that in the root directory, must be left without the change so it will have the original $_SERVER['DOCUMENT_ROOT']
that is public_html
. 但是必须保留根目录中的第一个站点,而该站点必须保持不变,因此它将具有原始的$_SERVER['DOCUMENT_ROOT']
为public_html
。
I am trying to change the .htaccess
that under the /site2
directory, but didn't find any solution yet. 我正在尝试更改/site2
目录下的.htaccess
,但尚未找到任何解决方案。
Can you help, please? 你能帮忙吗?
You could globally override that variable within PHP, by using the php.ini auto_prepend_file setting, which can also be set using .htaccess again: 您可以使用php.ini auto_prepend_file设置在PHP中全局覆盖该变量,也可以再次使用.htaccess进行设置:
php_value auto_prepend_file ./override_docroot.php
And that script would then "globally" adapt your environment: 然后,该脚本将“全局”适应您的环境:
<?php
$_SERVER["DOCUMENT_ROOT"] = "...";
But I really recommend you to create your own constant like "APP_BASE_URL" like this: 但我确实建议您创建自己的常量,例如“ APP_BASE_URL”,如下所示:
define('APP_BASE_URL','http://www.mywebsite.com', FALSE);
And then call it like: 然后像这样调用它:
<img src="<?php echo APP_BASE_URL; ?>/img/path/img.jpg">
Gook Luck! 祝你好运!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.