如果htaccess的声明 [英] htaccess if statement

查看:177
本文介绍了如果htaccess的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的.htaccess 文件中的以下行来选择要使用的PHP版本:

I have the following line in my .htaccess file to select which version of PHP to use:

AddType x-httpd-php53 .php

这伟大工程环境中生活,但并不适用于测试环境,并打破了现场。

This works great in the live environment but doesn't apply to the test environment and breaks the site.

有没有一种方法,我可以把它放在一个,如果服务器或网站什么的网址的IP陈述或东西,所以它只能生效环境中生活?

Is there a way I can put it in an if statement or something by IP of the server or URL of website or something so that it only comes into effect in the live environment?

推荐答案

的Apache 2.4 ,很容易与<如果> / <否则> 指令(?关于%{HTTP_HOST}

With Apache 2.4, it is easy with <If>/<Else> directives (on %{HTTP_HOST}?).

<If "%{HTTP_HOST} == 'foo'">
    # configuration for foo
</If>
<Else>
    # default configuration
</Else>

对于的Apache 2.2 并较早,我会一个参数之一添加到Apache( -D 选项)的启动命令行两个环境然后进行测试,如果它是present或不通过&LT; IfDefine&GT;

For Apache 2.2 and earlier, I would add a parameter to the startup command line of Apache (-D option) in one of the two environments then test if it is present or not via <IfDefine>.

要做到这一点在Windows上,使用Apache作为服务启动,修改关键注册表 HKEY_LOCAL_MACHINE \ SYSTEM \ ControlSet001 \服务\ Apache2的&LT; VERSION&GT; \的ImagePath
通过追加 -DFOO 。然后,你可以写:

To do this on Windows, with Apache started as a service, modify key registry HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Apache2.<VERSION>\ImagePath
by appending -DFOO. Then, you can write:

<IfDefine FOO>
    # configuration for foo
</IfDefine>
<IfDefine !FOO>
    # default configuration
</IfDefine>

这篇关于如果htaccess的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆