InMotion Hosting Support Center

A permanent 301 redirect in your .htaccess file lets search engines and others know that an old link has been replaced by a new one. It's the recommended method for directing traffic from an existing page.

Some common uses of a 301 .htaccess redirect:

You have the ability to setup redirects for a domain in your cPanel interface one link at a time. You can also add the redirects manually by modifying your .htaccess file directly.

Getting to your .htaccess file

On a Linux server you would use your .htaccess file to implement a 301 redirect for your pages.

  1. Login to your cPanel.
  2. Under Files, 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.
 

Redirect individual files

To redirect individual files, like example.com/oldfile.htm to newfile.htm you can use a 301 redirect like this:

Redirect 301 /oldfile.htm /newfile.htm

single file 301 redirect

To redirect one specific file to another domain such as example.com/oldfile.htm to example.net/newfile.htm:

Redirect 301 /oldfile.htm http://example.net/newfile.htm

single file domain 301 redirect

Redirect an old domain to a new domain

If you had an old domain such as example.com, and now you decided you actually want to use example.net for the website. You could setup a 301 redirect for the entire domain, so that old links to example.com carry over.

Code in the example.com domain's .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.net/$1 [L,R=301,NC]

full domain 301 redirect

Force www. version of domain to be used

A search engine like Google would see example.com and www.example.com as essentially two separate websites. They recommend you pick one version you'd like search engines to display and using a 301 redirect is a possible option.

If you have a lot of links on the web where people are linking to your site as example.com, but you would like your visitors to instead end up at www.example.com you can force this version of your domain with these rules:

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

force www 301 redirect

Force non www. version of domain to be used

If you have a lot of links on the web where people are linking to your site as www.example.com, but you would like your visitors to instead end up at example.com you can force this version of your domain with these rules:

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

force non www 301 redirect

Redirect all files with certain extension

To re-direct all of one type of file to another, such as example.com/file.php to example.com/file.htm

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

file extension 301 redirect

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.

Support Center Login

Social Media Login

   
Social Login Joomla
n/a Points
2016-12-02 8:05 am

Hello,

Can anyone can help me with somthing.. i need to merge 2 domain, and i have redirect domain1.com to domain2.com, domain have the same post... and i enter to domain1.com/post1 redirect to domain2.com a not to domain2.com/post1, how fix this??

Please help

Staff
2,679 Points
2016-12-02 11:51 am
n/a Points
2016-12-09 10:05 am

I have a doubt, is there a way to redirect example.com to en.example.com but still be able to access pages like example.com/articles/example ? 

Thanks in advance for your help.

Regards.

Staff
2,679 Points
2016-12-09 11:30 am
That should be possible, but as this issue has to do with the coding of your site or sites, we are not able to advise you on the exact code to do so. You will want to work with an experienced web developer, if you don't have one already, to assist you in addressing this issue.
n/a Points
2016-12-12 5:03 am

Hi thanks for sharing this great post. I have a query. please help if anyone can.

I want to redirect few webpages from my old domain to new domain. 

example: www.xyz.com/aboutus to www.xyz.org or www.xyz.org/newpage 

is this possible through the htaccess?

 

Thanks,

Prashant 

Staff
43,611 Points
2016-12-12 4:15 pm
Yes Prashant, that can be done. Examples are in the post above.
n/a Points
2016-12-21 5:47 am

Hi,

I have a requirement to remove my context path from the url

e.g.:

test.hostname.com/contextpath/page1test.hostname.com/contextpath/page2?content=1

the above urls should be accessed without the contextpathtest.hostname.com/page1test.hostname.com/page2?content=1

Can anybody help me to figure this out?

 

 

 

Staff
37,711 Points
2016-12-21 9:42 am
Hello Rajkumar,

You would need to use a Rewrite rule in the .htaccess file to rewrite that path so that it appears without the context path. The only difference is that you're not changing the query string. This tutorial on the Apache RewriteRule and query string does a good job of explaining it.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2017-01-17 12:10 am

Whenever I try to add or remove redirects CPanel says it can't do it because there are errors in the .htaccess file, so I have to go make the edits myself. But if I make the edits myself, like add a redirect, nothing happens. I need to redirect from vpgd.net/atcs to http://hotspotssoutheast.com/atcs. The edit is in the .htaccess file but it needs to be restarted or something? Not sure. Thanks.

Staff
8,146 Points
2017-01-17 3:29 pm
You may need to clear your browser cache. It's possible content is being saved locally.
n/a Points
2017-01-21 6:49 pm

Hello, I had the http:// version of my site but I bought an SSL certificate so now have the https:// prefix. How do I make sure that people who visit the http:// address get sent to the https:// site.

I don't have any money to spend yet so I need to do all this stuff myself but I'm still quite new to self hosted Wordpress so I need all the help I can get at the moment.

Thanks so much!

Staff
43,611 Points
2017-01-23 6:06 pm
You can set the https right inside your WordPress General settings. This should redirect it for you.
n/a Points
2017-01-25 8:06 pm

Thanks!

n/a Points
2017-01-25 1:35 am

Hi, I want to redircet my old webiste www.netsolutionsindia.com to a new domain www.netsolutionshq.com.Please help me out gow i can do it. The new website has new pages and structure as compared to the old website. Please guide on this.

Staff
12,692 Points
2017-01-25 8:52 am
Well, you have two different approaches and both have different effects on SEO. The first and easiest would be to follow the section above "Redirect an old domain to a new domain" and redirect any traffic from the old TLD (Top Level Domain) to the new TLD. This is fairly straight forward and easy to do. The problem is, you would lose the SEO value of the pages you already have ranking in the old website. The alternative, is to set up individual 301 redirects for each page in the old website. Each page would need to point to the respective page in the new site. This will pass most of the SEO value on to the new page.

n/a Points
2017-02-02 7:19 am

Thank you for clearing my doubts. However can I redirect my old blogs from netsolutionsindia to netsolutionshq.com ? Will that create a duplicate content issue? Curently I have linked the blogs on my new website to the old website as presently both website are working. Please help me on this.

Staff
28,243 Points
2017-02-02 9:52 am
Google recommends using 301 redirects to let search engines know this is a permanent redirect. Read more here.

Thank you,
John-Paul
n/a Points
2017-01-25 3:36 pm

Thank you for this very clear article!

I am currently redirecting users from a work server that will be discontinued in a few months to my personal domain at GoDaddy. The work server admin has set up a 301 redirect for me and it seems to be working well, but I am concerned about what will happen when the old server goes away. The 301 redirects are so smooth that I think users will not realize that they should update their bookmarks.

Is there any way I can create a popup message or an intermediate landing page at my GoDaddy domain to remind users to update their bookmarks, while still retaining the 301 redirect function?

Thank you for any advice you can give me!

Staff
37,711 Points
2017-01-25 6:00 pm
Hello Pat,

It is natural for old URLs to change especially after being re-directed for awhile. My recommendation is that you have the redirects in place as long as possible. Make sure that you are: 1) informing people about the new location and 2)displaying the new location in the browser when you re-direct them. You should put your reminder on the website where you're redirecting. As long as you've done your due diligence with the 301 redirects, then it should be okay. This will be best not only for your customers but also for the search engines where the links must also change.

I hope that helps to answer your question! If you require further assistance, please let us know!

Regards,
Arnel C.
n/a Points
2017-01-26 2:32 pm

Hi,

We are transitioning to WordPress and we would like to redirect around 60 products from our previous shopping cart. What we need is this:

Redirect from ourdomain.com/product-name to ourdomain.com/products/product-name using the .htaccess file.

Thank you very much for your help.

Staff
28,243 Points
2017-01-26 3:46 pm
Since WordPress relies on .htaccess rules/rewrites, adding custom rules can interfere with the functionality of the website. Instead, we recommend using a plugin to create 301 redirects from the old pages to the new ones.

Thank you,
John-Paul
n/a Points
2017-01-26 4:00 pm

Any recommendations on a good plugin to achieve this?

Staff
28,243 Points
2017-01-26 4:21 pm
I recommend trying several to see which one works best with your specific WordPress setup. There are many 301 redirect plugins available, view them here. Ensure it compatible with your version of WordPress.

Thank you,
John-Paul
n/a Points
2017-01-31 12:25 am

Hello, 

 

I am looking to redirect my homepage only but only when not logged into Wordpress. I am able to redirect the homepage right now using: 

RedirectMatch ^/$ http://google.com 

 

How can I only redirect the homepage for those not logged in? 

 

Thanks! 

Staff
12,692 Points
2017-01-31 9:05 am
This link may help you:

http://wordpress.stackexchange.com/questions/131879/how-to-redirect-non-logged-in-users-to-a-specific-page
n/a Points
2017-02-01 1:41 am

Thanks Tim! I gave it a try and it didn't seem to work for me. I'll keep researching it though. I was trying the two examples given on that website on the same sheet as my RedirectMatch. I'm not sure if that is where I would put the code. I also tried adding it to my functions.php page and that didn't work either. 

Staff
37,711 Points
2017-02-02 5:38 am
Hello Will,

Sorry for the issues with the re-direct. If the solution that Tim referenced earlier didn't provide enough of a description then you can also check this reference from the WordPress Codex. It may provide the solution you need.

If you have any further questions, please let us know.

Kindest regards,
Arnel C.
n/a Points
2017-03-04 4:47 pm

Hi, I recently created a new website under a new domain name. MOST of the old content has a counter-part page on the new site although the content was revamped and a few pages consolidated. How should I best redirect traffic given that the URLs will not match up (i.e. not as simple as switching from .com to .net)? Do I need to put lines in .htaccess for each URL? How would requests to the main landing page be redirected?

Thanks so much!

Staff
43,611 Points
2017-03-06 4:36 pm
Yes, for the individual pages that do not have a counter-part, you will need a specific redirect rule. Then, at the end, you can have the general rule so that it gets everything else.
n/a Points
2017-03-09 1:39 am

Great thanks!!! It worked for me!

n/a Points
2017-05-10 11:14 am

What is the best method to redirect from one domain to another if we are going to take down an old site and redirect the domain name? Both htaccess and 301 redirect comes to mind. I am trying to wrap my mind around where to send as the redirect in the domain settings. We want to send people to a specific page, not just the home page. Does anyone know if we can send people that type in a domain that we are redirecting and all pages requested go to a page on another site we already have? 

 

Redirecting domain: www.emulation.com

Desired redirect: www.isipkg.com/emulation

 

Can this be done? If so how? What about a wildcard send that has emulation.com/anything.html in the URL?

 

Thanks, Tom

Staff
37,711 Points
2017-05-10 12:20 pm
Hello Tom,

The article above covers the condition that you are referring to. You should give a period of time where the old domain URL is being redirected to the new one and you alert your viewers. If you intend to shut down the website where the URL is hosted and your new site is already running, then you may want to consider renewing the old domain temporarily if you do not have a sufficient period of time to alert your users to the change. Here's one article that discusses best practices for 301 redirects. Also, you may want to review Google's take on the subject here.

If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2017-05-11 12:10 pm

Thanks man, I just though that itsetad of installing a plugin, why nit do some coding and it took less time to redirect a page from .htaccess file as compare to install a plugin and add an entry.

Staff
28,243 Points
2017-05-11 2:19 pm
Since many CMS' (such as WordPress, Joomla, Drupal, etc.) rely on .htaccess rules, there are times when rules can can interfere with functionality. If you begin experiencing issues, then I do recommend using a plugin as a test.

Thank you,
John-Paul

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

721 Questions & Comments

Post a comment

Back to first comment | top

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!