Redirecting site using apache configuration
<yambe:breadcrumb self="Redirecting sites">Apache web server configuration</yambe:breadcrumb>
Redirecting site using apache configuration
There are many ways of reidrecting websites using apache. Most of them are discussed at http://www.yolinux.com/TUTORIALS/ApacheRedirect.html The two important ways of redirecting websites among the ones mentioned at given URL are
Using mod_alias
Redirect permanent / http://www.new-domain.com/
Using mod_rewrite
RewriteEngine On RewriteRule /.* http://www.new-domain.com/ [R]
mod_rewrite is very powerful and can achieve powerful results. For detailed help on mod_rewrite visit https://httpd.apache.org/docs/current/rewrite/
Redirecting based on IP address
RewriteEngine On RewriteCond %{REMOTE_ADDR} 193.189.116.235 RewriteRule !/block.* http://anusaaraka.iiit.ac.in/block/ [R] RewriteCond %{REMOTE_ADDR} 79.186.193.82 RewriteRule !/block.* http://anusaaraka.iiit.ac.in/block/ [R] RewriteCond %{REMOTE_ADDR} 10.2.59.228 RewriteRule !/block.* http://anusaaraka.iiit.ac.in/block/ [R] RewriteCond %{REMOTE_ADDR} 46.22.173.101 RewriteRule !/block.* http://anusaaraka.iiit.ac.in/block/ [R]
Here if incoming request is from 193.189.116.235 or 79.186.193.82 etc. IPs and the request is not starting with /block, then the user is permanently redirected to /block. This kind of redirection can be used to block few very irritating IPs who might be using bots etc. for DOS attacks and when blocking the same using firewall is not desirable. Using this we can display a message from http://anusaaraka.iiit.ac.in/block, so that if any legitimate users get blocked by mistake, they know what to do to get unblocked.
Now an alias such as
Alias /block /home/anusaaraka/block <Directory "/home/anusaaraka/block"> Options All AllowOverride All Order allow,deny Allow from all </Directory>
can be added to serve blocked index.html from some other folder. This is useful when blocking attackers on servers were drupal, etc. CMS are installed and URLs get modified. Add these config as high in the httpd.conf as possible, so that it has precendence over other aliases and rules.
<yambe:breadcrumb self="Redirecting sites">Apache web server configuration</yambe:breadcrumb>