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!
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.
This should do it:
RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !new-example.com$ [NC] RewriteRule ^(.*)$ http://new-example.com/$1 [L,R=301]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With