Enable access only to certain ip addresses

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Enable access only to certain ip addresses

03 Jul 2014, 04:51

Hi

I have a rule like this:

RewriteEngine on
RewriteBase /
RewriteRule ^backend/(.*)$ http://ipaddress:8088/backend/$1 [NC,P]

It works.

Now I want to disable access to "backend" app to all remote address except the internal ones.
Which is the right directive to use?

thanks

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Enable access only to certain ip addresses

03 Jul 2014, 05:26

Hello,

Please try to use the following syntax:

RewriteEngine on
RewriteBase /
RewriteCond %{REMOTE_ADDR} (?:list|allowed|ip|addresses|here)
RewriteRule ^backend/(.*)$ http://ipaddress:8088/backend/$1 [NC,P]

User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Re: Enable access only to certain ip addresses

15 Jul 2014, 04:55

it works

thanks

User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Re: Enable access only to certain ip addresses

18 Jul 2014, 13:44

Which is the right syntax to separate ip addresses?

Thanks

User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Re: Enable access only to certain ip addresses

18 Jul 2014, 14:04

and also:
if i have more webapplication that can be accessed by those ip addresses, it is possible to define the rule one?

for example:
RewriteCond %{REMOTE_ADDR} (?:IP)
RewriteRule ^admin/(.*)$ http://InternalIP:8080/admin/$1 [NC,P]
RewriteRule ^backend/(.*)$ http://InternalIP:8080/backend/$1 [NC,P]

If I write this way, the second rewriterule doesn't consider the ip filter.

Thanks

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: Enable access only to certain ip addresses

23 Jul 2014, 12:51

I think you'd need to repeat the rewritecond before the second rule.

I wonder whether, if this gets unwieldy, it would be better to use a rewritemap for the IP addresses instead of a list?

User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Re: Enable access only to certain ip addresses

25 Jul 2014, 04:39

I doon't know if i'm right, but i think there are some directive (like NC and P) that can be used to decide which is the last rule that should be considered for that rewrite condition.

Example:
RewriteCond %{REMOTE_ADDR} (?:IP)
RewriteRule ^admin/(.*)$ http://InternalIP:8080/admin/$1 [something here to tell that above condition shoul be used also for the following rules]
RewriteRule ^backend/(.*)$ http://InternalIP:8080/backend/$1 [something here to tell that above condition shoul not be used anymore for the following rules]

User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Re: Enable access only to certain ip addresses

03 Sep 2014, 13:17

Up

Thanks

User avatar
Posts: 22
Joined: 15 May 2014, 10:23

Re: Enable access only to certain ip addresses

22 Sep 2014, 05:19

Using multiple lines like this:
RewriteCond %{REMOTE_ADDR} (?:first_ip)
RewriteCond %{REMOTE_ADDR} (?:second_ip)
RewriteCond %{REMOTE_ADDR} (?:third_ip)

will allow access only to 3rd ip

I'm looking for a single line with multiple ip

Thanks

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 23 guests