.htaccess 文件中的 IP 范围

发布于 2024-09-25 09:01:56 字数 164 浏览 0 评论 0原文

我想使用此网络功能访问 IP 范围:.htaccess 文件和 RewriteCond 中的 68.241.45.0/20。像这样的事情:

RewriteCond %{REMOTE_HOST} !^68.241.45.0/20

但它似乎不起作用。

I want to get access to a IP range with this net feature: 68.241.45.0/20 in .htaccess file and in RewriteCond. Something like this:

RewriteCond %{REMOTE_HOST} !^68.241.45.0/20

but it doesn't seem to work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还在原地等你 2024-10-02 09:01:56

使用 RewriteCond 你只能做正则表达式或字典比较。由于 68.241.45.0/20 的范围是 68.241.32.1–68.241.47.254,因此您可以执行以下操作:

# regular expression comparison
RewriteCond %{REMOTE_HOST} ^68\.241\.(3[2-9]|4[0-7])\.\d+$

# lexicographic comparison
RewriteCond %{REMOTE_HOST} ^68\.241\.(\d+)\.\d+$
RewriteCond %1 >31
RewriteCond %1 <48

With RewriteCond you can only do regular expression or lexicographic comparison. And since 68.241.45.0/20 is the range from 68.241.32.1–68.241.47.254, you could do this:

# regular expression comparison
RewriteCond %{REMOTE_HOST} ^68\.241\.(3[2-9]|4[0-7])\.\d+$

# lexicographic comparison
RewriteCond %{REMOTE_HOST} ^68\.241\.(\d+)\.\d+$
RewriteCond %1 >31
RewriteCond %1 <48
っ左 2024-10-02 09:01:56

RewriteCond 在第二个参数上使用正则表达式。因此,您需要转义点 (.) 并使用正则表达式作为范围。

^68\.241\.[32|47]\.[1|2]?[0-9]+?

RewriteCond uses regular expression on the second parameter. So you need to escape the dots (.) and use regex for the range.

^68\.241\.[32|47]\.[1|2]?[0-9]+?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文