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,858 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,858 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,761 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
39,641 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
9,466 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,761 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
13,572 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
29,747 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
39,641 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
29,747 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
29,747 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
13,572 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
39,641 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,761 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
39,641 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
29,747 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
n/a Points
2017-05-31 8:29 am

Redirecting domain: www.new.com to www.old.com

Browser address field show : www.new.com

Thank you !

Staff
39,641 Points
2017-05-31 11:01 am
Hello Xman,

If you're trying to redirect to a new domain, use the options provided in the second option in the article above. If you have any further questions, please let us know.

Kindest regards,
Arnel C.
n/a Points
2017-06-14 6:17 am

hello sir,

Sometime ago i change my web themes use custom post that need a slug. ex

www.aaa.com/bbb.html change to www.aaa.com/slug/bbb.com. how can i return to my old www.aaa.com/bbb.html ? . FYI i run a lyrics website..

 

thanks in advance..

Staff
39,641 Points
2017-06-15 6:44 am
Hello, Rein,

If you're trying to redirect to a new URL but keeping the old one, then you need to use a rewrite. Checkout this tutorial for more information.

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

Kindest regards,
Arnel C.
n/a Points
2017-06-19 10:22 am

Hello Arn, you've been quite wonderful on this post assisting others and wondered if you could point me in the right direction on this issue?  

The old site is Joomla site on oldname.com domain. It hasn't been updated in several years and a total mess, throwing up errors and warnings.

New redesigned site and content is on Wordpress with newname.com domain with a new domain/web hosting company.  We'll work through creating the 301 redirects per your instructions above.  

Though the new site has newname.com as it's domain, we would ideally like to use the oldname.com domain for the new site.  

It sounds like for SEO purposes, we should leave the redirects active for a little while on the oldname.com's web hosting server, and don't do anything with the oldname.com domain for now. Then after a period of time, we can point the oldname.com domain to the new nameservers?  

Or can we point to the new nameservers now and just leave the oldname.com web hosting active during this transition?

Appreciate your thoughts!

Staff
29,747 Points
2017-06-19 10:56 am
Yes, we recommend keeping the old domain up for a while to allow you to continue 301 redirecting to the new site. It is okay to point the nameservers over, as long as there are 301 rules in place at the location you are pointing.

Thank you,
John-Paul
n/a Points
2017-06-27 8:23 am

This is clearly written, thanks for this!

However I have a site that no longer exists but I still need to redirect that traffic over to another site folder. I used. 

Redirect 301 / http://newdomain.com/new-folder

Which works, the www.oldsite.com is replaced with www.newsite.com but if someone has bookmarked an address that is not changed so

www.oldsite.com/some/random/bookmark becomes www.newsite.com/some/random/bookmark. Which gets Page does not exist. Quite right too, it doesn't exist. How can I get everything and there are many pages just replaced with http://newdomain.com/new-folder.

Appreciate your input.

Staff
9,466 Points
2017-06-27 8:40 am
The easy, but tedious, way would be to add a rule for each URL you want to redirect. Or, you could have a developer build some custom rules that take into account the directory structure of your site and achieve the result you need.
n/a Points
2017-07-05 7:50 pm

Hi There,

Thanks for the information.

I have a question if you could help me.

I have created a new website but without http version my old websited opens up.

How can i resolve http issue.

 

Cheers Komal

Staff
29,747 Points
2017-07-06 3:28 pm
If you want to only use the SSL, you can force https using the .htaccess file. If you are using a CMS such as WordPress, Drupal, Joomla, etc. you should make the change in their admin dashboard.

Thank you,
John-Paul
n/a Points
2017-07-11 3:51 pm
Can the code above be used for redirecting with https as well?
Staff
9,466 Points
2017-07-11 4:07 pm
Yes, it should be the same. You may also want to check out our full guide on using .htaccess to force https.
n/a Points
2017-07-12 5:39 am

Actually, I have a website using https and I want to move it to a new domain using Https too.

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

Is this code will work for moving https site to new https site?

Staff
39,641 Points
2017-07-12 12:28 pm
Hello Raghav,

I checked on this issue in several forums and the one that best explains it can be found here. I hope this helps to clarify the issue. If you have any further questions or comments, please let us know.

Regards,
Arnel C.
n/a Points
2017-07-18 3:23 pm

Those .gifs are confusing. Im spending alot of time trying to understand them. they move too fast for me. 

Thats my first minor complaint here in a year. I really have enjoyed this service. Thank you for providing all of this information. you guys are very helpful

n/a Points
2017-07-24 2:46 pm

How can i redirect my site to another server hosting without change nameserver because i want ti keep old server for emails. I want to build new site with PyroCMS and doesn't work on the old server

Staff
29,747 Points
2017-07-25 8:26 am
You can do this by pointing the 'A record' for your domain to the IP of the other host.

Keep in mind, if your MX record is pointed to that domain you should create a new entry to use for email.

For example, create a subdomain such as "mail.example.com" (be sure to replace example.com with your actual domain).

Point the 'A record' for "mail.example.com" to your shared IP address.

Then, use "mail.example.com" for your mx record such as:
0 mail.example.com

Thank you,
John-Paul
n/a Points
2017-07-26 2:21 pm

Hi I have a question about redirects. is it possible to create the following redirect: 

 

OLD URL: www.example.com/venue/washingtonDC 

NEW URL: www.example.com/venue/washington-district-of-columbia. 

 

Please note the same domain. 

Staff
1,239 Points
2017-07-26 2:53 pm
Hi, Richard!

You should be able to use the following code:

Redirect 301 /venue/washingtonDC /venue/washington-district-of-columbia

to make that redirect happen. Simply add that to the top of your .htaccess file for the domain. This should force www.example.com/venue/washingtonDC to redirect to www.example.com/venue/washington-district-of-columbia (on the same domain).

If that doesn't work for you, then you may be using a Content Management System (CMS) that would need to be configured according to the software's documentation, to implement that redirect behavior. I hope this helps!
n/a Points
2017-07-26 4:15 pm

Is there an article that you can send me that would help explain the process? I was told that can't happen. 

Staff
1,239 Points
2017-07-26 5:06 pm
Hi, Richard!

Thanks for your comment. If the redirect does not work via the standard .htaccess code I provided, then I would need to know what Content Management System (CMS- like BoldGrid/WordPress, Joomla!, Drupal, etc) you used to build the site. With that information, I can review our Support Center and/or the CMS's documentation to possibly assist you further. Can you advise which CMS you used to build the site, in the original location?
n/a Points
2017-08-10 10:59 pm

nice article :)

n/a Points
2017-08-14 4:15 am

Excellent information,

Very useful support to the website redirections up a 301 permanent redirect via htaccess files setup.

n/a Points
2017-08-23 1:48 am

Hi

I am unable to fing the .htaccess folder in cPanel. I am trying to force a https connection on my website.

Thanks

 

Staff
13,572 Points
2017-08-23 7:38 am
If there's not an .htaccess file in your directory you may need to show hidden files or create one if there's not one hidden.
n/a Points
2017-08-26 5:53 am

Will the code below direct example.com to example.net AND also FORCE NON WWW version of example.net to be used?

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]

Staff
9,466 Points
2017-08-26 9:12 am
The syntax looks good, but I advise double-checking with our full guide on forcing www with .htaccess.
n/a Points
2017-08-30 3:59 am

I am using this code then redirect only hostname non-www to www.

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

Now I want to redirect from  shop.local/shop/en/store to www.shop.local/shop/en/store

Staff
9,466 Points
2017-08-30 11:05 am
You should be able to just redirect the domain to www. All other relative paths should follow.

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.

760 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!