50

I want to redirect all of my old domain request to my new domain using htaccess file. Below is what I am using but it does not work if the page is not on the new site. For example google index about.htm on the old site but on the new site it does not exist. I would like it to just go to the root in all cases. I know this is not ideal for seo but I don't want any 404s. Any suggestions?

Redirect 301 / http://www.thenewdomain.com/
Richard JP Le Guen
  • 28,364
  • 7
  • 89
  • 119
Brian Barthold
  • 1,593
  • 4
  • 22
  • 39
  • 2
    possible duplicate of [.htaccess 301 redirect all pages on old domain to a single page on new domain](http://stackoverflow.com/questions/15057146/htaccess-301-redirect-all-pages-on-old-domain-to-a-single-page-on-new-domain) – mattdm Jul 10 '14 at 03:04

6 Answers6

84

If your aim is to redirect all pages to a single maintenance page (as the title could suggest also this), then use:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$ 
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.php [R=302,L] 

Where 000 000 000 000 should be replaced by your ip adress.

Source:

http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

MattAllegro
  • 6,455
  • 5
  • 45
  • 52
29

Are you trying to get visitors to old.com/about.htm to go to new.com/about.htm? If so, you can do this with a mod_rewrite rule in .htaccess:

RewriteEngine on

RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]

Community
  • 1
  • 1
kj.
  • 430
  • 4
  • 3
  • 1
    no i just want old.com/about.htm to go to old.com and then if possible remove the /about.htm so it just goes to the old.com – Brian Barthold Aug 19 '10 at 15:11
17

This will direct everything from the old host to the root of the new host:

RewriteEngine on
RewriteCond %{http_host} ^www.old.com [NC,OR]
RewriteCond %{http_host} ^old.com [NC]
RewriteRule ^(.*)$ http://www.thenewdomain.org/ [R=301,NC,L]
bjudson
  • 4,073
  • 3
  • 29
  • 46
6
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ "http://www.thenewdomain.com/" [R=301,L]
Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
3

HTAccess to send all pages of a website to one page. This worked for me:

ErrorDocument 404 /page-name.php

or to a different domain...

RedirectMatch 301 ^/.*$ https://www.example-domain.com/page-name.php
Chris9
  • 157
  • 1
  • 6
1

Add this for pages not currently on your site...

ErrorDocument 404 http://example.com/

Along with your Redirect 301 / http://www.thenewdomain.com/ that should cover all the bases...

Good luck!