I am looking to migrate from old domain to new domain.
I have my old domain olddomain.com
and new domain newdomain.com
pointing to same ip address for now.
I have Apache server inplace to handle requests.
How do I 301 redirect
all my
olddomain.com/*
&
www.olddomain.com/*
to
newdomain.com/*
Can I get exact regex or configuration that I need to add in htaccess
.
My newdomain.com and olddomain.com both are being serverd by same apache from same IP so "/" redirect might lead to cycles? And so was looking for effecient way
I tried
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost$ [OR]
# RewriteCond %{HTTP_HOST} ^www.olddomain.com$
RewriteRule (.*)$ http://comp16/$1 [R=301,L]
</IfModule>
And even tried adding in virtual host
RedirectMatch (.*)\.jpg$ http://comp17$1.jpg
But it does not redirect site when i hit localhost in browser to my computer name i.e comp16
To 301 Redirect an Entire Domain:Replace http://www.new-domain.com/ with the URL that you would like your site to redirect to. Be sure to add a blank line at the end of your . htaccess document.
Instead of using multiple domains to display the same page, you can instead redirect them to the main one. Migrating to a new domain. Again, you can permanently redirect an old domain to a new one by using a 301 redirect type.
I also recommend to use an If statement as you can use it also in a multisite server. Just type:
<If "%{HTTP_HOST} == 'old.example.com'">
Redirect "/" "https://new.example.com/"
</If>
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