• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

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:


forwards to :


What's the best way to do that in .htaccess?
1 Solution
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/
andythecalAuthor Commented:
And will that redirect and keep the URL? It won't just send them to the home page of the site?
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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.


www.domainold.com/*anything here*


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

Sorry, I probably confused the issue!
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?
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

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

andythecalAuthor Commented:
When I got my head round it, the original answer did the trick!

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now