mod_rewrite Redirect Domain (Only GET + HEAD)

/ Published in: Apache
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  1. RewriteCond %{REQUEST_METHOD} ^(GET|HEAD) [NC] # Only rewrite GET requests
  2. RewriteCond %{HTTP_HOST} olddomain\.com [NC]
  3. RewriteRule ^(.*)$$1 [L,R=301]
  5. RewriteCond %{HTTP_HOST} olddomain\.com [NC] # Otherwise block
  6. RewriteRule ^(.*)$ - [F]

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.