.htaccess 仅当 IP 地址未列出或不是特定 url 时才重定向
我正在尝试设置一个暂存子域,并且只想允许访问某些 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将单独的 .htaccess 文件放入 /api/foo
您的 .htaccess 文件可能如下所示:-
You can put a separate .htaccess file inside /api/foo
Your .htaccess file might look like so:-