简体   繁体   English

根据Web应用程序在其上运行的服务器使用其他.htaccess文件?

[英]Use a different .htaccess file depending on the server the web application runs on?

I have a test-server and a production-server. 我有一个测试服务器和一个生产服务器。 I need different .htaccess files for test and production. 我需要不同的.htaccess文件进行测试和生产。 On test I want the PHP 'display errors' to be on, but I don't want that on production of course. 在测试中,我希望打开PHP“显示错误”,但我当然不希望在生产中使用。

I know I can set 'display errors' in PHP too, but then I have to do that in each script that I run. 我知道我也可以在PHP中设置“显示错误”,但是然后我必须在我运行的每个脚本中都这样做。 Doing it with : 这样做:

php_flag display_errors On

in .htaccess in the root folder is much easier. 在根文件夹中的.htaccess文件中,操作更加容易。

So my question is, how can I make 2 different .htaccess files and depending on the server automatically use the right one? 所以我的问题是,我该如何制作2个不同的.htaccess文件,并根据服务器自动使用正确的.htaccess文件?

Apache is using a configuration directive to find these files: Apache使用配置指令来查找以下文件:

AccessFileName .htaccess

So if you change your development server with 因此,如果您使用以下命令更改开发服务器

AccessFileName .htaccessdev

in /etc/apache2.conf , then you can handle 2 versions of settings, one for production in .htaccess and one for development in .htaccessdev . /etc/apache2.conf ,那么你可以处理2个版本的设置,一个生产在.htaccess和一个在.htaccessdev发展。 Security filters are usually fine and defined this way: 安全过滤器通常很好,并通过以下方式定义:

<Files ~ "^\.ht">
  Order allow,deny
  Deny from all
</Files>

which covers both names. 其中涵盖了两个名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM