2

I am sure this is pretty simple, but i just cant find the right code for it.

I need to redirect everything, old domain, with and without www all sub pages.any random link that may be out there to www.newdomain.com

Here is mine at the moment, and it redirects well, exceprt for one thing www.old-doamin.com/old-page - redirects to www.newdomain.com/old-page

When it should be going to the home page of the new page.

thank you for the help.

RewriteCond %{HTTP_HOST} ^old-domain.com/$
RewriteRule (.*) http://www.old-domain.com/$1 [R=301,L]

RedirectMatch 301 ^/(.*)http://www.newdomain.com/$1

2 Answers2

0

Why dont you do it through DNS? CNAME redirect would probably be best so the old-domain.com traffic is redirected?

If you want to go with htaccess, this should do the trick:

RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/ [L,R=301]
Sam Leach
  • 72
  • 7
  • I tried this solution and it didn't work. http://www.olddomain.com/pagethat-no-longer-works.html redirects to http://www.newdomain.com/pagethat-no-longer-works.html I need a redirect the redirects everything .. including all sub pages to the home page of the new domain. – Judd lehmkuhl Oct 15 '13 at 12:18
  • See here, this looks more like it, I have updated my answer to match http://stackoverflow.com/questions/15057146/htaccess-301-redirect-all-pages-on-old-domain-to-a-single-page-on-new-domain – Sam Leach Oct 15 '13 at 15:59
0

Make www optional, this should work for you:

RewriteCond %{HTTP_HOST} old-domain\.com$ [NC]
RewriteRule ^ http://www.newdomain.com/ [R=301,L]

Don't forget to take out both of your existing rules.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I tried this solution and it didn't work. http://www.olddomain.com/pagethat-no-longer-works.html redirects to http://www.newdomain.com/pagethat-no-longer-works.html I need a redirect the redirects everything .. including all sub pages to the home page of the new domain. – Judd lehmkuhl Oct 15 '13 at 12:21
  • Which URL didn't redirect to newdomain? This rule will redirect all the URs that have `old-domain.com` in domain. – anubhava Oct 15 '13 at 13:04
  • it redirected to the new domain, but with the old page url.. that page does not exist on the new site.. – Judd lehmkuhl Oct 15 '13 at 14:49
  • Ok please check the edited answer now. Make sure to test it in a different browser. – anubhava Oct 15 '13 at 15:00