htaccess 显示不同 ip 的不同根
我有以下 .htaccess
文件:
RewriteEngine On
RewriteCond ${ipmap:%{REMOTE_ADDR}} ^allow$ [NC]
RewriteRule ^ - [F,L]
我想知道是否可以将 IP 从列表重定向到另一个文件夹,但它们仍然看到相同的 URL (example.com
) 而不是 example.com/folder
。
I have the following .htaccess
file:
RewriteEngine On
RewriteCond ${ipmap:%{REMOTE_ADDR}} ^allow$ [NC]
RewriteRule ^ - [F,L]
I would like to know if it's possible to redirect the IP's from the list to another folder but they still see the same URL (example.com
) and not example.com/folder
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行以下操作:
您不需要在与重写映射匹配的规则上使用
NC
。 (假设您的地图始终使用allow
,而不是任何其他混合大小写版本?)如果所有内容都将重写到
/folder
并且您没有引用/folder
之外的任何静态资源,那么您也许可以删除执行文件系统检查的两个条件(以测试请求是否尚未映射到文件或目录)。作为额外的好处,您可以阻止用户直接访问
/folder
并使用类似以下在上述重写之后的内容重定向回根目录(紧接在>RewriteEngine
指令):(注意:这假设您在
/folder
子目录中没有另一个包含 mod_rewrite 指令的.htaccess
文件。如果您那么你需要而是在那个.htaccess
文件中执行此重定向。)You could do something like this:
You shouldn't need the
NC
on the rule that matches from your rewrite map. (Assuming your map is consistently usingallow
and not any other mixed case version of this?)If everything is to be rewritten to
/folder
and you aren't referencing any static resources outside of/folder
then you can perhaps remove the two conditions that perform the filesystem checks (to test whether the request does not already map to a file or directory).As an added bonus, you can prevent direct user access to the
/folder
and redirect back to the root with something like the following before the above rewrite (immediately after theRewriteEngine
directive):(NB: This does assume you don't have another
.htaccess
file in the/folder
subdirectory that contains mod_rewrite directives. If you do then you would need to preform this redirect in that.htaccess
file instead.)