通过.htaccess在服务器上存储常量变量 [英] store constant variable on server via .htaccess
本文介绍了通过.htaccess在服务器上存储常量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想以最简单的方式存储 INDEX_URL
常量。
I would like to store the INDEX_URL
constant the easiest way possible.
有一个开发人员网站,正常站点。如果开发人员站点上有任何更改,
我只想复制整个文件,但是在两个站点上此常数是不相同的。
There is a developer site and a normal site. If there is any change on the developer site, I would like to just copy the entire files but this constant is not the same on the 2 sites.
我做了这个测试:
putenv("TEST=TEST");
var_dump(getenv('TEST')); //TEST
//putenv("TEST=TEST");
var_dump(getenv('TEST')); //false
似乎没有存储值。
另一种方法:
define('__INDEX_URL__',"http://".$_SERVER['SERVER_NAME']."/index.php");
推荐答案
您可以将其另存为环境变量。将其放在.htaccess中:
You can save it as environment variable. Put this in .htaccess:
SetEnv INDEX_URL http://example.com/index.php
并在PHP中获取它:
$indexUrl = getenv('INDEX_URL');
这篇关于通过.htaccess在服务器上存储常量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文