top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

redirect based on internal or external IP using Apache

0 votes
1,115 views

I am new to apache, so forgive me if this is a beginner questions.

I am trying to redirect request to apache based on the IP address. Depending on where the request originates from, the request will either have a external or internal IP address. External will be redirected to the external site, internal will be redirected to the internal site.

Request to www.site.com will be evaluated based on the IP address. Then redirected to either www.site.com/external or www.site.com/internal . I am able to accomplish this with the following.

 RewriteCond %{REMOTE_ADDR} ^1.1.1.1 
 RewriteRule ^(.*)$ www.site.com/internal [R=301,L] 
 RewriteCond %{REMOTE_ADDR} ^2.2.2.2 
 RewriteRule ^(.*)$ www.site.com/external [R=301,L] 

The problem I am running into is that this is in a loop. Every request will be evaluated and redirected. If possible, I need a way to redirect once, then let other request (www.site.com/external/a/b/c or www.site.com/internal/x/y/z )not be evaluated and then redirected

posted Jul 1, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The way I would handle this is adding a second rewritecond to each stanza, looking at REQUEST_URI to make sure that the target path is not there, eg

RewriteCond %{REMOTE_ADDR} ^1.1.1.1  
RewriteCond %{REQUEST_URI} !^/internal  
RewriteRule ^(.*)$ www.site.com/internal [R=301,L] 
answer Jul 1, 2013 by anonymous
Similar Questions
0 votes

We have a small cluster of machines serving a wiki website. Search engine robots are allowed in to index the website and these create a lot of traffic that can affect the service. I would like to redirect all http requests from these robots to one of the machines in the cluster.

Any ideas for how to do this ?

+3 votes

We have integrated apache web server with our internal LDAP and we have requirement to provision role based access to the folders in the docroot. We have earlier used SVN and we were using AuthzSVNAccessFile to meet this requirement. Contents of the file will look like this.

[groups]
users = usera
admins = usera, userb
[/]
users = r

[/folderA]
admins= r

Now we are looking for something similar with the apache directives, is it possible? if not, can you please give us an alternate?

I have tried "Require ", it doesn’t solve our requirement.

+3 votes

I want to redirect a url to an application on same apache server. My development environment is Ubuntu. I enables the mod_proxy. But my url isnt redirecting to the desired application. Following is the code I put inside the /etc/apache2/sites-available/default file. I put this bottom of the file but before the "VirtualHost" tag.

ProxyRequests On 
ProxyVia On  
Order deny,allow 
Deny from all 
Allow from localhost  ProxyPass /application_directory/ http://localhost/application/directory ProxyPassReverse /application_directory/ http://localhost/application/directory 
+2 votes

Currently my Apache server supports SSLV2, V3, TLSV1. My client requirement is to enable TLSV1.1 or above on the webserver.

Current Version of Apache: Apache V2.2.16 When I tried to Add SSLProtocol All TLSv1.1 TLSv1.2. Server has thrown the error saying Illegal Protocol.

Please do let me know the steps for enabling TLSV1.1 or above.

0 votes

I am using CentOS 6.0 with Apache 2.2.15, and set up Apache with virtual host. The SSI works fine on the first VH, but ssi on the other virtual hosts does not work. I got the following message in the error log:

mod_include: Options +Includes (or IncludesNoExec) wasnt set, INCLUDES filter removed

Does anyone know how to resolve this problem?

...