301 Redirects on Apache maintaining URL

I've got a wordpress blog on an apache server that we're migrating to another domain (I've posted a similar question about IIS by the way). What we want to do is to forward to the new domain, but keep the URL intact. Therefore:

www.domainold.com/the-best-dogs

forwards to :

www.domainnew.com/the-best-dogs

What's the best way to do that in .htaccess?
andythecalAsked:
Who is Participating?
 
Frederic SuneCEO, IT in MIND inc.Commented:
For apache, you need to use htaccess configuration: put this .htaccess file on your old site to redirect to the new one:
# This allows you to redirect your entire website to any other domain
Redirect 301 / http://domainnew.com/
0
 
andythecalAuthor Commented:
And will that redirect and keep the URL? It won't just send them to the home page of the site?
0
 
Frederic SuneCEO, IT in MIND inc.Commented:
For the specific folder on the old domain, to the new domain:

Redirect 301 /the-best-dogs http://www.domainnew.com/the-best-dogs

Open in new window

0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
andythecalAuthor Commented:
Sorry, I probably didn't make it clear.

We have lots of pages on the old domain and we don't want to redirect each one, we want it to keep the URL and just redirect everyone to the new domain, but to the page they wanted.

http://www.domainnew.com/the-best-dogs was an example, but it could be anything after the domain so it's like a wild card.

Basically:

www.domainold.com/*anything here*

to

www.domainnew.com/*what was in the URL above*

Sorry, I probably confused the issue!
0
 
Frederic SuneCEO, IT in MIND inc.Commented:
Ok so you can use this htaccess on the old website:
Redirect 301 / http://www.domainnew.com/

But the main old domain, www.domainold.com, the root need to be accessible?
0
 
ramazanyichCommented:
you should better use RewriteEngine of apache.
Check http://httpd.apache.org/docs/2.2/rewrite/remapping.html
there is your use case explaned in the "Resource Moved to Another Server" section
0
 
arober11Commented:
Hi,  

The easiest solution would be to alter the DNS record of your OLD domain, to make it a CNAME (alias) for the new Domain, then assuming the new hosting provider permits you to have multiple host names associated with a single virtual host, you can access the new Wordpress instance using either domain name.

If this isn't an option then you'll want a 307, not a 301 redirect, from your old site to the new. A 307 is a temporary redirect that should preserve the existing Hostname in the URL bar, and allow any form data to also be redirected.

.htaccess entry:
RewriteEngine On
RewriteRule  .*   http://www.domainnew.com%{REQUEST_URI} [L]

Open in new window

0
 
andythecalAuthor Commented:
When I got my head round it, the original answer did the trick!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.