We Recommend

Pro Apache Pro Apache
In addition to installation, maintenance, and deployment, the book demonstrates how to configure Apache to use Perl, PHP, and Python as server-side scripting languages. And unlike other books on Apache, Pro Apache provides comprehensive information on both major revisions - 1.3 and 2.0 - of the software.


Posted By

DaveChild on 09/11/08


Tagged

redirection


Versions (?)


Who likes this?

2 people have marked this snippet as a favorite

Scooter
millisami


mod_rewrite Redirect Domain (Only GET + HEAD)


Published in: Apache 


Redirect all GET and HEAD requests to new domain (only redirecting GET and HEAD because POST, PUT, DELETE etc to old domain is almost certainly automated spam - no genuine users should ever be posting to old domain if it's been completely redirected). Serve 403 to any other request.

  1. RewriteCond %{REQUEST_METHOD} ^(GET|HEAD) [NC] # Only rewrite GET requests
  2. RewriteCond %{HTTP_HOST} olddomain\.com [NC]
  3. RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
  4.  
  5. RewriteCond %{HTTP_HOST} olddomain\.com [NC] # Otherwise block
  6. RewriteRule ^(.*)$ - [F]

Report this snippet 

You need to login to post a comment.