Posted By

DaveChild on 09/11/08


Tagged

redirection


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Scooter
millisami
nublaii


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.