Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect all request from old domain to new domain

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

like image 911
Amol Ghotankar Avatar asked Oct 14 '13 09:10

Amol Ghotankar


People also ask

How do I redirect a whole domain?

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.

Can you redirect to a different domain?

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.


1 Answers

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>
like image 81
K. Stopa Avatar answered Oct 26 '22 06:10

K. Stopa