允许基于HTTP:X-FORWARDED-FOR在htaccess中进行访问 [英] Allow access in htaccess based on the HTTP:X-FORWARDED-FOR

查看:84
本文介绍了允许基于HTTP:X-FORWARDED-FOR在htaccess中进行访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只应允许特定的IP地址(即HTTP:X-FORWARDED-FOR地址)访问文件.我已经通过以下方式完成了

Hi i should only allow the particular ip address(which is HTTP:X-FORWARDED-FOR adresses) to access the files. I have done it by the following

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP:X-FORWARDED-FOR} !^xxx.xxx.x.xx$
RewriteRule ^$ http://xxx.xxx.x.xx/access_denie.php [R=301,L]

现在我必须允许它用于多个IP,例如yyy.yy.y.yy.我如何使用htaccess做到这一点

Now i have to allow it for multiple ip for example yyy.yy.y.yy. How can i do it by using htaccess

推荐答案

RewriteCond^xxx.xxx.x.xx$部分只是一个正则表达式.您可以轻松地使用组来添加更多IP地址:

The ^xxx.xxx.x.xx$ portion of your RewriteCond is simply a regular expression. You can easily use groups to add more IP addresses:

^(xxx\.xxx\.x\.xx|yyy\.yy\.y\.yy)$

您会发现我用反斜杠转义了所有.,这是因为.在正则表达式中具有特殊含义,如果您只想让它匹配文字.字符.

You will notice I have escaped all the .s with a backslash - this is because . has a special meaning in a regular expression, and it needs to be escaped if you want it to match only a literal . character.

所以您的新RewriteCond看起来应该像这样:

So your new RewriteCond will look like this:

RewriteCond %{HTTP:X-FORWARDED-FOR} !^(xxx\.xxx\.x\.xx|yyy\.yy\.y\.yy)$

您可以轻松添加更多IP地址,只需将其与|字符分开即可.

You can easily add more IP addresses, simply separate them with | characters.

但是,请注意,这种方法并没有给您真正的安全性.欺骗请求来解决这个问题很容易.如果需要安全性,则应该使用SSL和适当的身份验证系统.

Please note, however, that this approach does not give you any real security. It would be easy to spoof a request to get past this. If you need security you should use SSL and a proper authentication system instead.

这篇关于允许基于HTTP:X-FORWARDED-FOR在htaccess中进行访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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