Archive for July, 2013

Redirect certain subnets to a different site in Apache.

I did this from the httpd.conf where I have all my virtual directories defined. I just added the following within one of those virtual directory definitions and reloaded httpd. This will redirect anybody on the 192.168.0.0/24 subnet to http://google.com, and the others will proceed to the directory (/my/website/directory).


RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^192.168.0.*
RewriteRule .* http://google.com [R=302,L]

In an .htaccess file you would just need to add the following:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^192.168.0.*
RewriteRule .* http://google.com [R=302,L]

If you need to redirect the cgi-bin, elsewhere:


AllowOverride All
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^192.168.0.*
RewriteCond %{REMOTE_HOST} !^172.16.0.*
RewriteCond %{REMOTE_HOST} !^10.0.0.*
RewriteRule .* http://www.google.com [R=302,L]
Options ExecCGI
Options FollowSymLinks
Order allow,deny
Allow from all

Sending email from PHP using mail().

To send text email from PHP:

tomailaddress‘;
$from = ‘frommailaddress‘;
$subject = ‘Here is my subject.’;
$message = ‘Some text in the body of the message.’;

$headers .= ‘X-Priority:1 (Highest)’ . “\r\n”;
$headers .= ‘From: ‘ . $from . “\r\n”;
mail( $to, $subject, $message, $headers) or print ‘Could not send mail’;
?>

To send HTML email from PHP:

tomailaddress‘;
$from = ‘frommailaddress‘;
$subject = ‘Here is my subject.’;
$message = ‘
<HTML>
<BODY>
<B>
Some bold text
</B>
<P>
Some other HTML stuff.
</BODY>
</HTML>
‘;

$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= ‘X-Priority:1 (Highest)’ . “\r\n”;
$headers .= ‘From: ‘ . $from . “\r\n”;
mail( $to, $subject, $message, $headers) or print ‘Could not send mail’;
?>

Return top

INFORMATION