Logo 
Search:

Unix / Linux / Ubuntu Answers

Ask Question   UnAnswered
Home » Forum » Unix / Linux / Ubuntu       RSS Feeds
  on Feb 06 In Unix / Linux / Ubuntu Category.

  
Question Answered By: Adah Miller   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}
^(?!192\.168\.)(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\.){3}(?:25[0-5]|2[0-4][0-\
9]|[01]?[0-9][0-9]?)$

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}
^(?!192\.168\.)(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\.){3}(?:25[0-5]|2[0-4][0-\
9]|[01]?[0-9][0-9]?)$
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.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

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


Tagged: