[英].htaccess rules by IP address
I'm looking for a way to enable some .htaccess rules on an IP or hostname basis (hopefully with regex). 我正在寻找一种基于IP或主机名启用某些.htaccess规则的方法(希望使用正则表达式)。 This is all over stackoverflow, but I can't find any that are generic rules that apply to a block of rules (And in fact, that may not be how .htaccess works. I'm not sure!). 这是整个stackoverflow上的问题,但是我找不到适用于规则块的通用规则 (实际上,.htaccess的工作方式可能不是。我不确定!)。
I do NOT need a rewrite rule. 我不需要重写规则。 I do NOT need access/deny flags. 我不需要访问/拒绝标志。 I just want to change some PHP flags and file behavior for some development IP addresses on a few of our servers. 我只想更改一些服务器上某些开发IP地址的一些PHP标志和文件行为。
For example, to enable debug mode /error_log/ 例如,启用调试模式/ error_log /
<magical_ip_filter_tag "123.456.78.901">
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag log_errors on
php_value error_log /home/path/public_html/domain/PHP_errors.log
</magical_ip_filter_tag>
Note that I do not need a PHP solution for PHP debugging, this is just an example. 请注意,我不需要用于PHP调试的PHP解决方案,这只是一个示例。
You will usually find many comments/posts saying this is not possible. 通常,您会发现许多评论/帖子说这是不可能的。 That would have been possible easily in newer Apache versions (2.4 and newer). 在较新的Apache版本(2.4及更高版本)中,这很容易实现。
However on older Apache 2.2*
This is something I have used as a workaround solution 但是,在较旧的Apache 2.2*
这已用作解决方法
Create a symbolic link of /index.php
and name it something like /myinde.php
using this command: 创建/index.php
的符号链接,并使用以下命令将其命名为/myinde.php
:
ln -s index.php myindex.php
Add this code in your DocumentRoot/.htaccess
: 将此代码添加到您的DocumentRoot/.htaccess
:
RewriteCond %{REMOTE_ADDR} ^123\\.456\\.78\\.901$ RewriteRule !^myindex.php/ myindex.php%{REQUEST_URI} [L] <Files myindex.php> php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on php_flag log_errors on php_value error_log /home/path/public_html/domain/PHP_errors.log </Files>
RewriteRule
on top forwards all the requests from your IP address to /myindex.php
making original URI available as PATH_INFO
. 最上面的RewriteRule
会将来自您IP地址的所有请求转发到/myindex.php
从而使原始URI作为PATH_INFO
可用。
Then block of code inside <Files myindex.php>
is executed for the file myindex.php
. 然后,对文件myindex.php
执行<Files myindex.php>
内部的代码块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.