In this article we'll discuss using the .htaccess file which can control Apache's mod_rewrite module to help rewrite and redirect URLs on the server. We'll focus specifically on what are called 301 permanent redirects in this guide.

A 301 permanent redirect is a way to tell search engines on the Internet that one URL has been replaced permanently by another. A common need for a 301 permanent redirect is if you're switching domain names, or changing linking structures. You want to make sure that all of the backlinks and traffic you've earned on the old URLs don't suddenly disappear once making the change.

You can setup redirects for a domain in your cPanel interface one at a time, or following the steps below you can modify your .htaccess file directly to add these manually yourself.

Getting to your .htaccess file

  1. Login to your cPanel.
  2. Under the Files section, click on File Manager.
  3. Select the Document Root for: option, and choose your domain from the drop-down.
  4. Ensure that Show Hidden Files is selected.
  5. Then click Go.
  6. file-manager-hidden-files
     
  7. Right-click on the .htaccess file and select Edit.
  8. file-manager-htaccess-edit
     
  9. If your .htaccess file didn't exist already during the previous step, click on New File at the top-left, name the file .htaccess, and finally set the directory for the file to be created to /public_html/ or the document root of your site.
  10. file-manager-htaccess-create
     
  11. You might have a text editor encoding dialog box pop-up, you can simply click on Edit.

Making your .htaccess edits

  1. With the .htaccess file opened for editing you can now begin to type in your redirect code.

    To 301 permanently redirect an entire domain you could simply enter in the following format:

    Redirect 301 / http://NewDomain.com

    This would cause typing in OldDomain.com/path/to/file.htm to load up in your web-browser as NewDomain.com/path/to/file.htm.

    Or if you'd like to just redirect individual files you could set those up to either point to new files on the same domain, or ones on a completely different domain as well using the following format:

    Redirect 301 /oldfile.htm /newfile.htm
    Redirect 301 /oldfile2.htm http://NewDomain.com/newfile2.htm
    

    This would cause typing in OldDomain.com/oldfile.htm to load up in your web-browser as OldDomain.com/newfile.htm, and typing in OldDomain.com/oldfile2.htm would bring you to NewDomain.com/newfile2.htm

    Finally you can also use the more advanced RewriteCond condition statements and RewriteRule rules if you needed to redirect more dynamic content. In this next code snippet for instance, we are redirecting any URL that ends with .htm and rewriting that to the same request but ending in a .html extension instead.

    RewriteEngine On
    RewriteCond %{REQUEST_URI} .htm$
    RewriteRule ^(.*).htm$ /$1.html [R=301,L]
    

    This would cause typing in OldDomain.com/oldfile.htm to load up in your web-browser as OldDomain.com/oldfile.html.

  2. Once you are finally done making your edits to the .htaccess file, you can then click on Save Changes to save your edits.

You should now know how to properly setup 301 permanent redirects on your website to help ensure that search engines and visitors coming to your site from older links can still get to your new content.

Like this Article?

Login to comment.

Your Opinion Matters

... but we need to know what you're thinking!

I'm Jacob Nicholson, your friendly Community Support technician, and I wrote the article you're looking at now. I like to think it's perfect, but I'm sure you have some suggestions. Please, let me know what they are!

Feedback
Your Email Address
Because we'd like to talk with you!

Latest Questions

If you need some help, submit your question to our Community!
We guarantee a response within 60 minutes (8am - 9pm EST, Monday - Friday)
Ask a Question!
Recent Questions
  1. PHP Fatal Error message Out of memory.
  2. Email Account
  3. My domain name is in redemption. Can you help me recover it?

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!