We Need Website

Blog

  • WordPress
  • Hosting
  • Server
  • How to
  • Applications

How to 301 Redirects an Old Domain to your New Website using .htaccess Edit

Posted by Praan Kumar Leave a Comment

How-to Guide on 301 redirects and mod_rewrite to permanently move an old website to a new address without losing traffic.

Now don’t lose traffic also keep the Google bot happy as well. This guide will help you to ensure all the traffic to your old domain instantly redirect to the new domain. This helps you in keep trust in your brand rather than an ugly 404 error page or “Come Back Later” page” which nobody will come back again. Straight forward now goto the following codes into your .htaccess file. [Always remember, if your not an expert in editing a .htaccess file, keep a working backup of your website before touching any code. If somehow your site breaks, the habit of backing up will save your time & hard work.] Let’s get started.

Method 1:

Options +FollowSymlinks

RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]

Method 2:

Options +FollowSymlinks

RewriteEngine On
RewriteCond %{HTTP_HOST} \olddomain.com$
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]

Method 3:

Options +FollowSymLinks

RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Method 4:

Redirect 301 / http://www.newdomain.com/

That’s was the methods. Now know how this simple code keeps the Search Engines bot happy.

Whenever a search bot come to crawl your website and finds that the domain returns a 404 error page or website don’t load anymore, the bot informs the Search Engine like Google, Yahoo, Bing, Duckduckgo, etc. that the web address is no longer available means the website is dead. Thus the Search Engines promptly removes the webs pages from their index. If this happens, then the traffic coming to your old website go in vain. By the way, you can still redirect and regain reputation by forwarding the old site to your new website. If you redirect your old domain, then Google also updates its index as the change of address which helps you to preserve the old rankings. Not only that the search engines also know the all inbound links point to your old website passes the juice, PageRank and other attributes to the new one and thus preserving your reputation among the users.

How to Edit .htaccessfile on your server

If you don’t know how to edit the .htaccess file on your server where the advanced server settings are controlled.

If you use WordPress CMS, then install the “File Manager” plugin to access the files of your website on the server. If you don’t use WordPress, then connect to your server using your favourite FTP client. My Favorite FTP client is FileZilla. For shared hosting, you can directly access your Cpanel.

In the main root directory usually, it is public_html or www there is already a file exit called .htaccess. In shared hosting you may not see the file even it exists, in that may sure that your hidden files are visible or marked as shown from your Cpanel settings. In WordPress or Cpanel, you can directly edit the file from your Cpanel dashboard or plugin dashboard. But in FTP client FileZilla, you can’t make directly right select and edit them. Therefore you need to upload or update a new .htaccess file via FTP client method in the case of hosting providers(VPS) where direct access or Cpanel is not given.

Note: I would strongly recommend making a backup of your .htaccess file, just in case things went wrong.

For WordPress and other CMS of static website, append the code beneath the line RewriteEngine On.

To edit in FTP client like CuteFTP, FileZilla download the already existed .htaccess file on your desktop and make a backup copy of it. Rename the original .htaccess file as htaccess.txt as windows can’t understand or may not open the .htaccess filename. If you don’t have already a .htaccess file, then don’t worry, just create a htaccess.txt file on your Desktop. Make changes to the text file and upload it then rename as .htaccess again to make the effect.

For example, I have shown here the example on Method 2 to how your .htaccess file should look like-

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond %{HTTP_HOST} \olddomain.com$ 
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L] 
RewriteBase / RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] </IfModule>

Please keep the following in mind in regards to updating your .htaccess file

  • Always be sure to upload .htaccess files in ASCII mode. Using binary in your FTP client will likely cause problems and make your server unhappy. Most FTP clients should do this automatically.
  • If .htaccess does not work, there’s a good chance you’re on a Windows server and will need to use other methods!
  • Many operating systems don’t allow you to create a file without something before the “.” — in this case, you would be best to save the file as htaccess.txt and change it once you’ve uploaded it to your server via your FTP client.
  • Ensure your FTP client shows .htaccess files (FileZilla does and is free). Some FTP clients require you to turn this option on manually.
  • Double-check that you’re not overwriting an old .htaccess file (many servers already place one there for any custom 404 pages and so forth.)
Share this

Filed Under: Coding, How to guide

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 5 Top Marketplaces To Sell Domain & Websites
  • Black Friday Web Hosting Deals 2020 Offer, Discount, Coupon, Promocode
  • Grow your Business & Sales with e-Storekeeper. Create a Digital Store Online
  • Top 7 Keyword Research Tools For SEO for 2020-21
  • Top 10 Best Free Online HTML Table Generator/ Editors

Recent Comments

  • Mr S7jk on How to Setup Freenom Domain (.tk, .ml, .cf, .ga, .gq) on Blogger Platform?
  • Sarrah on List of Instagram Web Viewer Script | How to Check Profile without Login
  • Praan Kumar on Step by Step Guide How to Install WordPress on Subdirectory on Cloudways
  • Faiz Alias on Step by Step Guide How to Install WordPress on Subdirectory on Cloudways
  • Joe on How to Setup Freenom Domain (.tk, .ml, .cf, .ga, .gq) on Blogger Platform?

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Copyright © 2021 We Need Website | Privacy Policy . About Us . Contact Us

Login