2

I want to 301 redirect from: www.olddomain.com to the root of newdomain.com but I want it to work no matter what the folder path is on the old domain. eg: the following should all redirect to the root of newdomain.com

www.olddomain.com
olddomain.com
www.olddomain.com/folder/file.php
olddomain.com/folder/file.php

How can I do that with Mod Rewrite in the .htaccess file?

Greg
  • 316,276
  • 54
  • 369
  • 333
Matthew James Taylor
  • 4,806
  • 5
  • 29
  • 33

2 Answers2

8

Try this rule:

RewriteEngine on
RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$
RewriteRule ^ http://new.example.com/ [L,R=301]

Where old.example.com is the old host name and new.example.com the new.

Gumbo
  • 643,351
  • 109
  • 780
  • 844
0
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>

This should also work for you.