.htaccess 仅当 IP 地址未列出或不是特定 url 时才重定向

发布于 2024-09-11 05:31:47 字数 558 浏览 0 评论 0原文

我正在尝试设置一个暂存子域,并且只想允许访问某些 IP 地址,但允许每个人访问以 /api 开头的任何 url。

下面的内容适用于 IP 地址,但如果我尝试使用未列出的 IP 地址访问例如 /api/projects/api/users ,则始终会重定向。

任何帮助将不胜感激。

RewriteEngine On
RewriteBase /

RewriteCond %{REMOTE_HOST} !^11\.11\.11\.11
RewriteCond %{REQUEST_URI} !/api*
RewriteRule ^.*$ http://domain/ [R=302,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I'm trying to setup a staging subdomain and only want to allow access to certain ip addresses, but allow everyone access to any url starting /api.

What I have below works for the ip address, but always redirects if I try and access for example /api/projects or /api/users with an ip address not listed.

Any help would be greatly appreciated.

RewriteEngine On
RewriteBase /

RewriteCond %{REMOTE_HOST} !^11\.11\.11\.11
RewriteCond %{REQUEST_URI} !/api*
RewriteRule ^.*$ http://domain/ [R=302,L]

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

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

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

发布评论

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

评论(1

你的心境我的脸 2024-09-18 05:31:47

您可以将单独的 .htaccess 文件放入 /api/foo

您的 .htaccess 文件可能如下所示:-

order deny,allow
deny from all
allow from 1.2.3.4
allow from 2.3.4.5

You can put a separate .htaccess file inside /api/foo

Your .htaccess file might look like so:-

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