Unix / Linux / Ubuntu Forum

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds

apache redirect help

  Date: Feb 06    Category: Unix / Linux / Ubuntu    Views: 383

The school called me this morning with a internal problem.
Ive been reading apache tutorial today and havent seem to
have found the right combination yet.

The server they are using, they want to deny all, allow ONLY
internal 192 networks, and redirect anyone trying to access it
from ourside their ip range to something like google. (dont
ask me why, that is just what they are doing).

This is their directory file.

Anyone give me some help here.

Options Indexes FollowSymLinks
MultiViews AllowOverride None Order allow,deny Deny from All Allow
from ::1/128 Redirect /



4 Answers Found

Answer #1    Answered On: Feb 06    

I'm no Apache wiz, but it looks like the order should be deny,allow instead
of allow,deny. Otherwise you will be applying the deny all after allowing
your local connections. You want to deny all then allow the local
connections. Haven't tried redirect, so can't say about that.

Answer #2    Answered On: Feb 06    

I switched the allow,deny to deny,allow and its still letting things
through. It might have something to do with how they have their network

Answer #3    Answered On: Feb 06    

This has taken me a few hours of testing regular expressions and delving
into the apache documentation, but I think I have something for you. You
need to enable the rewrite module that will allow you to rewrite url's
based on regex criteria and variables that apache uses:

sudo a2enmod rewrite

Then you need to add 3 directives to your configuration. The first is:

RewriteEngine on

This should probably be added to your main site configuration file. Next,
the rewrite condition:

RewriteCond %{REMOTE_HOST}

This can be added beneath the previous directive in the main configuration
file or to the .htaccess file of any directory (if you only want to
redirect from certain areas in your site). This regex matches any ip
address except 192.168.*.* to the REMOTE_HOST variable. You'll want to
edit this to fit your situation. I used an online regex evaluator to test
it. Finaly, the rewrite:

RewriteRule .* http://www.google.com/

This substitutes http://www.google.com/ for any url the remote host is
looking for. The rewrite condition and rule need to be together either in
the main configuration file or the .htaccess file. So your configuration
would look something like this:

Options Indexes FollowSymLinks MultiViews
AllowOverride None
RewriteEngine on
RewriteCond %{REMOTE_HOST}
RewriteRule .* http://www.google.com/

You'll want to look at the documentation though, you may have more to think
about. Hope that points you in the right direction.
I don't think you can deny AND redirect though, but let me know how it goes.

Answer #4    Answered On: Feb 06    

You'll also have to restart the server with:

sudo /etc/init.d/apache2 restart

after you change the configuration file, but you probably knew that :)

Didn't find what you were looking for? Find more on apache redirect help Or get search suggestion and latest updates.