Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to 301 redirect an entire domain while preserving the path

Tags:

I am redirecting one domain to another, but I want to preserve the path in the redirect. So for example, I want to visit www.example.com/services/education/page.html, but my redirect will bring them to www.new-example.com/services/education/page.html. What do I write in my .htaccess file to preserve the path "/services/education/page.html"?

Right now I have:

redirect 301 http://www.example.com/ http://www.new-example.com/ 

But I'm not sure if that works or not (Can't test yet as I am waiting for domain details etc). I just want to be sure when I put the site live. Is that right or am I way off base?

Thanks!

like image 842
jasonaburton Avatar asked Dec 09 '11 19:12

jasonaburton


People also ask

Can you 301 redirect to another domain?

A 301 redirect is a permanent redirect from one URL to another. While they can redirect site page URLs, they can also redirect from one domain to another.


1 Answers

This should do it:

RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !new-example.com$ [NC] RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301] 
like image 149
Eric Brandel Avatar answered Sep 27 '22 01:09

Eric Brandel