【问题标题】:htaccess - allow access to one ip to url that starts with /sample/, restrict everything elsehtaccess - 允许访问以 /sample/ 开头的 url 的一个 ip,限制其他所有内容
【发布时间】:2016-03-29 08:52:12
【问题描述】:

我正在尝试让 .htaccess 阻止所有 ip(除了一个)以访问任何不以 /sample/ 开头的路由。例如:

www.domain.com/ - unreachable to everyone

www.domain.com/test - unreachable to everyone

www.domain.com/sample/asdsd - reachable to one ip

这是我到目前为止得到的:

阻止所有访问:

Order Deny,Allow Deny from all

检查 url 是否带有 /sample/ 星号,如果是,则允许特定 ip 访问它:

<if url starts with www.domain.com/sample/> Allow from 127.0.0.1 </if>

我基本上被困在 if 语句上.. 有什么建议吗?

【问题讨论】:

  • 您应该为此使用 RewriteRule。

标签: apache .htaccess


【解决方案1】:

在您的根 .htaccess 中,您可以使用此 mod_rewrite 规则执行此操作:

RewriteEngine On

RewriteCond %{REMOTE_ADDR} !=127.0.0.1 [OR]
RewriteCond %{REQUEST_URI} !^/sample/ [NC]
RewriteRule ^ - [F]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 2016-10-22
    • 1970-01-01
    • 2016-12-02
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多