htaccess可以读取Apache中设置的服务器环境变量吗? [英] Can htaccess read a server environment variable set in Apache?
问题描述
在Apache设置中设置服务器环境变量时,可以使用内置函数从PHP读取该变量。
When you set a server environment variable in your Apache settings, it's possible to read that variable from PHP using built in functions.
但是可以从中读取变量吗? htaccess文件?
But can you read the variable from an htaccess file?
我要在htaccess中完成的工作大致如下:
What I'm trying to accomplish in my htaccess is something along the lines of:
<If var=="stuff">
do things here
</if>
<if var=="different stuff">
do different things here
</if>
推荐答案
是的。
您可能想使用mod_setenvif功能,因此需要打开该模块。
You will probably want to use mod_setenvif functionality, so that module will need to be turned on.
然后,您只需执行以下操作:
Then you simply do something like:
SetEnvIf Request_URI "\.gif$" image_type=gif
将环境变量 image_type
的值设置为 gif
如果请求的文件名以 .gif
结尾。
Which would set the environmental variable image_type
with a value of gif
if the requested file name ends with .gif
.
然后您可以访问它(例如在RewriteCond中)像这样:
You could then access this (like in RewriteCond) like this:
RewriteCond %{ENV:image_type} gif
RewriteRule ^(.*) $.gif
您可以在此处阅读完整的文档: http://httpd.apache.org/docs/2.2/env.html
You can read the full documentation here: http://httpd.apache.org/docs/2.2/env.html
这篇关于htaccess可以读取Apache中设置的服务器环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!