Skip to content

Redirect Old Domain To New Domain With .htaccess

Redirect Old Domain To New Domain With .htaccess

Assuming that your web server runs on Apache, which is pretty much the norm for any shared hosting service out in the wild, here’s how you can redirect your old domain name to a new one, while keeping your SEO juices.

Using any file editor available, edit the .htaccess file at the root folder, which is usually public_html .Add the following to the very start of the file, regardless of whether your .htaccess is empty or not

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomainhere.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomainhere.com$
  RewriteRule (.*)$ http://www.newdomainhere.com/$1 [R=301,L]
</IfModule>

The above will redirect the homepage, and any other pages. For example, the following

1. http://olddomainhere.com/
2. http://www.olddomainhere.com/
3. http://olddomainhere.com/redirect-old-domain-to-new-domain-with-htaccess

Redirects to the following respectively

1. http://www.newdomainhere.com/
2. http://www.newdomainhere.com/
3. http://www.newdomainhere.com/redirect-old-domain-to-new-domain-with-htaccess

Should you require any assistance, let me know in the comments below and I will try my best to help.

Enjoyed the content ? Share it with your friends !
Published inWeb Server

Be First to Comment

Leave a Reply

Your email address will not be published.