How to Set Up a 301 Redirect in .htaccess

301 Permanent Redirects Title Image

A permanent 301 redirect informs search engines and other online services that an old link has been replaced by a new one. It’s the recommended method for directing traffic from an existing page. This type of 301 redirect can be set up directly via the .htaccess file or in the cPanel interface, if available.

Common Uses of 301 Redirects

Some common uses of a 301 redirect in .htaccess:

  • Redirect individual files on the same domain.

    An old file has moved locations, or the information is now contained in a new file.

  • Redirect an old domain to a new domain.

    You’ve moved a website from an old domain to a new one, and you want any old links to go to the new site.

  • Force www. version of a domain or force non www. version of a domain.

    Visitors can access and link to your website through either example.com or www.example.com. With a redirect, you can set one of these as the preferred domain name that your site displays.

  • Redirect all files with certain extension.

    You used to have all of your files using an extension like .php and have converted everything to .htm so using a 301 redirect you can update all links to use the new extension.

Don’t have time to read our article on how to set up a 301 redirect? Watch our walkthrough video.

Set Up 301 Redirect via .htaccess file

On a Linux server you would use your .htaccess file to implement a 301 redirect for your pages. We’ll now show you how to edit the .htaccess file, then go over the different redirect options.

  1. Login to your cPanel.
  2. Under Files, click on File Manager.
    Access File Manager to Setup 301 Redirect in .htaccess
  3. Ensure that Show Hidden Files is selected by clicking Settings on the top right corner of the File Manager.
    View Hidden Files to See .htaccess
  4. Select the Document Root for: option, and choose your domain from the drop-down.
  5. Right-click on the .htaccess file and select Edit.
    Edit .htaccess File and Setup 301 Redirect
  6. If your .htaccess file is still not found after the previous steps, click on New File at the top-left, name the file .htaccess, and set the directory for the file to be created to /public_html/ or the document root of your site.
  7. You might have a text editor encoding dialog box pop-up, you can simply click on Edit to proceed.
    Edit .htaccess file - Setup 301 Redirect

Redirect 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 https://example.net/newfile.htm
single file domain 301 redirect

Redirect domain

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

Sample of code from example.com domain’s .htaccess file:

RewriteEngine on

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

Force www. on domain

A search engine such as Google interprets example.com and www.example.com as essentially two separate websites. It is recommended that users pick one version they’d like search engines to display. By using a 301 redirect, users can specify which domain name is displayed on their site.

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

RewriteEngine on

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

Force non-www. on domain

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

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301,NC]
force non www 301 redirect

Redirect files by 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.

Set Up 301 Redirect in cPanel

For users that host their sites on cPanel-based hosts, it is possible to set up redirects via the cPanel interface. This tool automatically adds the necessary code to the .htaccess file for the redirect to function properly.

  1. Login to cPanel.
  2. Click theĀ RedirectsĀ button in theĀ DomainsĀ section.
    301 Redirect Button cPanel
  3. You will then be on theĀ Add RedirectĀ page. Click the drop-down box forĀ TypeĀ and choose either aĀ Permanent (301)Ā orĀ Temporary (302)Ā redirect.
    301 Redirect Type cPanel
  4. Click the next drop-down box and choose the domain you want to redirect.
    301 Redirect Protocol cPanel
  5. For the slash ā€˜/ā€™ field, enter any folder names (if necessary).
  6. Enter the address you want to redirect to in theĀ Redirects toĀ section.
    301 Redirect Target cPanel
  7. Choose if you want to ā€œOnly redirect with www.ā€ ā€œRedirect with or without www.ā€ or ā€œDo Not Redirect www.ā€œ
  8. Check the box if you want to create aĀ Wild Card Redirect. This will add the the file/folder name after the url when it redirects. For instance, example.com/test.php would redirect to example2.com/test.php.
  9. ClickĀ AddĀ when finished.
    301 Redirect Save cPanel

Congratulations, now you know how to create a redirect in your cPanel! Did you know? If you have a WordPress site, you can also create a 301 redirect directly in your dashboard.

Know youā€™ll always be able to reach your customers when they need you with our Dedicated Hosting Services.

AK
Alyssa Kordek Content Writer I

Alyssa started working for InMotion Hosting in 2015 as a member of the Technical Support team. Before being promoted to Technical Writer, Alyssa developed expertise in the fields of server hardware, Linux operating systems, cPanel, and WordPress. She now works to produce quality technical content featuring cutting-edge topics such as machine learning, data center infrastructure, and graphics card technology.

More Articles by Alyssa

869 Comments

  • hi
    I want the following addresses in WordPress :

    *****.com/savabeg-mali-sherkat/amp

    be directed to the previous lesson :

    *****.com/savabeg-mali-sherkat

    • Hello Jojhelp – The directions in the article show you an example of how to re-direct a domain in the .htaccess file. It matches up with your pattern of URLs. Follow the directions to edit the .htaccess file and replace the domain so that it looks like this:

      RewriteEngine on

      RewriteCond %{HTTP_HOST} ^example.com/savabeg-mali-sherkat/amp [NC,OR]

      RewriteCond %{HTTP_HOST} ^www.example.com/savabeg-mali-sherkat/amp [NC]

      RewriteRule ^(.*)$ https://example.com/savabeg-mali-sherkat [L,R=301,NC]

      You can also create the redirect in the cPanel.

  • Hello Dear,
    I am Pasted that but my site cannot redirect,
    Please help

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^dubaivacancy.me [NC]
    RewriteRule ^(.*)$ https://www.dubaivacancy.us/$1 [L,R=301,NC]

    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

    # BEGIN WordPress

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    • Hello yasirr786,

      Thank you for your question. To clarify, are you receiving any sort of error message when attempting to set up the redirect or is it simply redirecting to the wrong place? You will also want to ensure that the .htaccess file is named properly and accessible from the document root of the website (usually the public_html folder).

      Best Regards,
      Alyssa K.

  • Till now, I was doing this via WordPress Plugin as I was unable to do it with Htaccess. But now its look like an easy go. Thanks for such a helpful guide.

  • Hi, I face an issue here. I tried with this
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    but redirection still not work, I’ve also perform few testing as below:
    – .htaccess has been enabled with AllowOverride and tested readable.
    – filename no issue.
    – location of rules has been move to beginning of the files but not work
    – Syntax tested with tool which available online and debug with no issue.
    I have no more idea what else to do now, please help :(((

    • Hi Petri, try using our standard recommendation for setting up a redirect:

      RewriteEngine On
      RewriteCond %{HTTPS} !on
      RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
      RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  • hi there. i am trying to figure out if it is possible to create htaccess redirect for all pages of a domain to an inner page of a new domain? i.e. olddomain.com and olddomain.com/allpages to newdomain.com/alltothisinnerpage,

    • Hello Nick,

      Thank you for your comment. Yes, it is possible to do this. All you need to do is redirect your old domain name to the URL of the page you want users to be redirected to. I recommend doing this in cPanel instead of directly in the .htaccess file. Please see the following guide for instructions on this task:

      https://www.inmotionhosting.com/support/domain-names/redirect-domain/

      Please let us know if you have any further questions, we are happy to help.

      Best Regards,
      Alyssa K

  • Hello,
    My http website has been moved to a secure protocol and it is now https. However I have a page in the site that has a search-by-address that links to an http site from another domain. This is not working because the site keeps directing the search to a secure page instead and that page doesn’t exist. Can I use a permanent Redirect for this page inside the site in htaccess?

  • Let me know, If i want that my visitors visit directly to my this page like https://root.com/example-page always instead of https://root.com homepage. For this how can i redirect this from htaccess file?? Have any way??

  • 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?

    • You would need to build the notification (pop-up or otherwise) on the page where you’re re-directing to. Once the re-direct is in place, all web traffic would not be able to get to the old page. Notificatons and pop-ups can be manually built or done through a plugin/extension. If you’re not familiar with development, then you should consult with an experienced developer.

  • I am facing too many redirects of 301 on same domain like https://www.mydomain.com/ same URL repeated too many times for that my website is getting an error in google index. Any body help me.

    • If you check this in a search engine several possibilities appear. It can result from issues with settings in your .htaccess file. You need to check your code in the .htaccess file for redirect loops. If you’re not familiar with how to do this, then you may need to consult with an experienced developer/programmer.

  • On a rewrite with over 50,000 pages with redirects on half of pages what is the best practice?  Is there a limit to the file size?  How long should you leave the redirects in the file? 

    • There is no limit on the file size, however, it will need to be balanced with the server load during high levels of traffic. If your visitors are each hitting a file that has 50,000 checks, it may cause the site to render more slowly if there are more visitors. For best practices, I recommend reviewing Moz.com as SEO experts their forums typically provide some good insight into best practices. I hope this helps!

  • Hi! I need some help please, I have a wordpress hosted site. I have moved my images from wp-content/uploads to media.mysite.com and I dont have any clue how  redirect the old folder to the new subdomain from htaccess. There should be like a 301 redirect code to tell search engines that ive moved my media files from the wp media folder to a subdomain. Could you please help me?  Thank you!

    • Below is a solution I found while researching online. I recommend trying this code in your .htaccess file where your WordPress installation is.

      RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [OR]
      RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
      RewriteRule ^wp\-content\/uploads\/?(.*)$ "http\:\/\/subdomain\.yourdomain\.com\/$1" [R=301,L]

      This should redirect all requests for the wp-content/uploads directory to the subdomain. However, you may need to customize this to work for your custom configuration.

      I hope this helps!
      Sincerely,
      Carlos D.

  • Hello,

    Good Blog for the 301 permanant redirection. i want to remove my all the pages .php extention and want to add “/” slash in end of the every url. can you help me in this.

     

    • The proper way to do this depends on how the website was built. What software did you use to build your website?

  • How do i redirect the url https://superbanswer.com to https://www.superbanswer.com

    is it posible with .htaccess?? any idea?

  • hi i have a problem please answer to me

    i want to redirect my old domain www.takhteh-nard.xyz to new domain www.takht-online.xyz but when i use rediret code google not accept this code. you k’now what is this problem?

    • If you’re using the “ahref” as your code then it is not a redirect. Please review this article as it provides the redirect code that can be used in your .htaccess file. If Google continues to refuse it, then you may need to send them a message for clarification of the issue.

  • Hi, very helpful article.

    I have one issue here and I would like your help. Due to rebranding reasons we bought a new domain name. I have accomplished to redirect all the requests from www.siteA.gr to www.SiteB.com but I want to do the same for all the old pages and URL in order to redirect them to the same URL / path under the new site.

    For example if someone goes to www.siteA.gr/about.html to be redirected to www.siteB.com/about.html or www.siteA.gr/career/ to be redirected to www.siteB.com/career/ etc. There are dozens of URLs and I want to avoid to write specific redirect rules for each one of these. Is there any generic redirect rule that I could use to do it simultaneously for all the URLs?

    thanks

    • Hello,

      i, very helpful article.

      I have one issue here and I would like your help. Due to rebranding reasons we bought a new domain name. I have accomplished to redirect all the requests from www.siteA.gr to www.SiteB.com but I want to do the same for all the old pages and URL in order to redirect them to the same URL / path under the new site.For example if someone goes to www.siteA.gr/about.html to be redirected to www.siteB.com/about.html or www.siteA.gr//career/ to be redirected to www.siteB.com/career/ etc. There are dozens of URLs and I want to avoid to write specific redirect rules for each one of these. Is there any generic redirect rule that I could use to do it simultaneously for all the URLs?

      It sounds like you have already accomplished that if you’re redirecting all of the requests to the new domain name. If you’re trying to avoid having to re-write paths so that they show a specific path (e.g. www.siteB/about.html), then you will need to make sure that the same exact folder structure exists in your new site. Then, it would be a simple matter of replacing the old domain with the new one. If you are running into problems with with the paths, then there has been a change in how your files are located in the new location. Make sure that your files and folders are named the same and in the same location under the new domiain.

  • I have a question:
    I have old urls with subdomain prefixes, example:
    https://argentina.example.net/index.php?route=common/home&tracking=gusph

    that I would like to permanently redirect to:

    https://www.example.net/ar/?ref=gusph

    could you please help?

    Thanks in advance for your prompt response.
    regards,

  • Hello,

    I migrated from http to https recently and although the site is working perfectly,  when I upload the new version, which I reverified as a new identity with Google Console, the new version show different number of internal links and “links to your site”. I finished the transition process in WordPress with “Real Simple SSL plugin” did that not change the settings?  Is there another step I am mising? I  am still seeing people accessing the http version too.

    Many thanks for your help,

     

    • Hello,

      If you are forcing HTTPS, it may be that you have pages cached that are not HTTPS. Check your URL using a utility site like Why No Padlock? It should identify any unsecure links. Make sure to clear any caching on your site. If you continue to have problems then you should first try our live technical support team or speak with an experienced website developer/programmer.

  • Hello, if migrating my site from olddomain.com at old hosting company, to newdomain.com with a new hosting company, will I need to keep my old hosting account active while the 301 redirect is in place? Or do I simply need to maintain my olddomain.com registration, without hosting? Thank you!

    • In order for the redirect from olddomain.com to continue to redirect to newdomain.com, you will need to host that 301 redirect on a server somewhere. Whether that is your old host or new host, it doesn’t matter. However, if you cancel your hosting for olddomain.com then the redirect will no longer function.

  • How i can redirect old visitor to new url, because the old url is index so much, i want to redirect the user to new url via .htaccess? Any solution, thanks.

    So if they are browsing article for example: https://www.example.com/web/my-article, redirect to this: https://www.example.com/my-article

    Thanks

  • I’ve moved a website from an old domain to a new one and used .htacces to direct any old links to go to the new site.

    Do I need to save old domain name rented also, or I can stop paying for the old domain?

    • For the 301 redirect to continue working you will have to keep the old domain registered.
      Thank you,
      John-Paul

  • how to fix my issue in my website working with www and non www with /index.php file i tried many code but all failed

    https://example.com/index.php

    • Hello! Thanks for posting your comment regarding your website’s functionality using www and non-www URLs and /index.php. I’m sorry to see that you are experiencing issues with that. The code in this guide is intended to generally assist with this. However, if you are using a CMS (like WordPress, Joomla!, Drupal, etc) the code may not work.

      To reiterate, if you want to force all traffic to go to www.example.com, you will need to add the following code to the top of your .htaccess file:

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

      You may also be able to select to hide the /index.php portion of the URL depending on the CMS you are using. If you can reply with which CMS you are using, we may be able to assist you further.

  • Hello,
    I am trying to redirect a site. most of the pages are redirected by “Redirect” one page to another. but I have a lot of old pages with no pare on the other side.
    I would like to redirect all of those pages to the new homepage.com
    how can I redirect all of them as long as they are not ion the list of the regular Redirect lines?

    • That code is very specific and would require a custom solution. Therefore, I recommend reviewing the Apache documentation to determine the code you should use. Otherwise, I suggest finding a developer to write that specific code for you.

  • I have a question:  How do I build a 301 redirect in my .htaccess file for the following.  My DOMAIN is www.vintagevogue.com  My ecommerce was located at: https://www.vintagevogue.com/onlinestore.  My new ecommerce is located at https://www.vintagevogue.com/pres156.  I want to ensure anyone going to the OLD ecommerce files will be redirected to my NEW ecommerce files.  All of the file names have changed along with the pictures from /onlinestore to /pres156.  So basically I’m trying to ensure if anyone goes to the /onlinestore that they be redirected to /pres156.  Any assistance you can provide would be greatly appreciated.  Thank you !!!

    • You would use the old domain to new domain example in the tutorial above. You would simply need to include the entire path for the old and new locations.

  • i’m chnge my forum root from

    shneler.com/vb/ to shneler.com/ 
    

    I’d like to redirect subdirectory (vb) to a main domain without losing the index in google. Example:

    www.sneler.com/vb/node/post.no1  to www.shneler.com/node/post.no1
    

    and please note i have 20000 post thread in my forum already archive in google index

    • You can use the old URL to NEW url displayed in the tutorial above. You would simply need to make sure that the URL you are using in the rewrite rule includes the subdomain you wish to use. If you want more information about 301 redirects and how it helps to preserve your ranking, please see this article.

  • Hi, i’ve tried doing 301 redirect from your above example on my new design website. How can I undo the code? if I type the domain name without the “www.”. Your Example.net keeps showing up.. How can I undo this? Please Help!!

  • Hi

    How to redirect every single file from all directories and with all extensions from old site to the homepage of the new site?

    Thanks

    • Your best bet likely be a domain redirect at the root level. There are instructions above on how to do that.

  • Hello. 

    I am moving all content from my site/domain jimmyfuentes.com to a new site / domain . I am using updraft plus to migrate it so everything will literally be exactly as it was on jimmyfuentes.com with the only difference being the root domain. 

    I need to put 301 redirect in the htaccess for jimmyfuentes.com for EVERYTHING except for the root domain  of jimmyfuentes.com because I am going to be  building new and different content on jimmyfuentes.com . Basically, How do I 301 all of the old page urls, image urls, etc but keep the root domain jimmyfuentes.com and any future pages I build on jimmyfuentes.com safe ?  

    Thank you for any and all help

    • The redirects described in this article will not work in the manner that you are asking about. This is because you would need to redirect each file using the code:

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

      However, this would restrict you to only making files on the “old” domain that have a unique name from the “new” domain. Also, this would require that you set a redirect for each file, which is tedious. Otherwise, there is no way to accomplish what you are describing.

    • You are welcome! We are glad to see that this article was able to help you. Please feel free to let us know, “Was this article helpful?” by clicking the “Yes” or “No” button located above the article you would like to leave feedback on. Your feedback ensures we are able to continue to provide helpful content! Thanks.

  • I checked every possible reason/option but our site links to another website if we use https://websitename. I cannot find the reason. It is not an alias, not redirecting also. It only happens when using https:// not when using https://. Please enlighten me and help me to solve.

     

    • The SSL certificate used for the HTTPS URL can be assigned to a specific IP address. If this IP address is different from your non-HTTPS URL, then the website may look different. You will need to directly speak with your host’s support team to double-check your URL in order to determine why the URLs are going to different locations. The live technical support team can be contacted as per the information at the bottom of this page.

  • thanks so much. The code worked. I am greatful and so happy that al referals links on our website are finally redirecting to the new link with the same structure. LOVE YOU GUYS

  • I have redirected my site https://freeasp.net to https://cheaperasp.net via htaccess using your guide. Both of my sites are on WordPress. Now I want to login to my old site i.e FreeASP to access some information but when I am typing the login URL, it is redirecting to my new site. Kindly help how can I access my old site.

    • You need to create an exception rule for the login URL that processes BEFORE the general re-direct. It should specify the login URL so that you can get to it before the redirect to the new site URL processes.

  • How it is possible to redirect any old domain to a new one. There are some old domains I don’t no anymore but on the new server there are a lot of 404s. Iwant to redirect any domain without setting a specific name

    Thank you

    Regards

    Andreas

    • We have some redirect rules listed above under the heading “Redirect an old domain to a new domain” in order to handle that request.

  • I want to redirect permanently my https://techonmech.com/ this domain to my another domain https://wittynow.com/. Can you please tell me how can I do this. Any trick or possiblity to redirect my first domain to the second one. Please help me..

    • Redirect instructions for this case are provided in the above article under the heading “Redirect an old domain to a new domain.”

  • Great job! Very helpfull, but i have a doubt:

    I want to redirect the https://www to https://www

    In that case, please, verifu if i did right doing this: (for security purpose, i hide the domain after the www.)

    # BEGIN WordPress

    <IfModule mod_rewrite.c>

    Options +FollowSymLinks

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^https://www./ [NC]

    RewriteRule ^(.*)$ https://www./$1 [L,R=301,NC]

    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /index.php [L]

    </IfModule>

     

    # END WordPress

     

     

    Thanks

    • Hello,

      If you want to redirect all of that path to the root domain then you go into cPanel and use the wildcard to represent the different folders or files in the URL. Keep in mind that if you want to use a 301, then you are basically telling search engines that this is a permanent change. Do not use a 301 redirect if you are not changing the paths.

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

      Kindest regards,
      Arnel C.

  • Awesome site and kudos for so generously helping folk. I’ve added the code to my .htaccess file and now oldname.com goes to newname.com perfectly. However, weirdly, the posts are not going though – they are resolutely oldname.com/posts and will not re-direct. The post naming structures are definitely the same…  I’ve tested with multiple posts by simply changing the ‘newname’ to ‘oldname’ bit of the URL. Any suggestions? And many thanks.

    • We’re always happy to help! It sounds like you are trying to change the domain for your website, rather than change one URL/file/path to be redirected. Due to how WordPress sites are designed, you can not simply change and redirect the URL. As you can see the posts and other components may not work properly. I can recommend you try using the Velvet Blues Update URLs plugin to update your URLs when changing the domain name of your website. This will not require any redirects.

      Otherwise, I recommend you contact a third party developer to write code to customize the behavior you want for your domain redirect.

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

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://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

  • 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 ^(.*)$ https://example.net/$1 [L,R=301,NC]

  • Hi

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

    Thanks

     

  • Excellent information,

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

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

    • 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?

  • 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. 

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

  • 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

    • 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

  • 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

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

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

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

    • 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.

  • 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

  • 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 / https://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 https://newdomain.com/new-folder.

    Appreciate your input.

    • 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.

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

    • 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

  • 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..

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

    Browser address field show : www.new.com

    Thank you !

    • 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.

  • 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.

    • 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

  • 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

    • 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.

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

    • 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.

  • 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.

    • Google recommends using 301 redirects to let search engines know this is a permanent redirect. Read more here.

      Thank you,
      John-Paul

  • 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. 

    • 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.

  • 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 ^/$ https://google.com 

     

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

     

    Thanks! 

    • This link may help you:

      https://wordpress.stackexchange.com/questions/131879/how-to-redirect-non-logged-in-users-to-a-specific-page

    • 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

  • 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.

    • 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

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

    • 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.

  • 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.

    • 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.

  • Hello, I had the https:// 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 https:// 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!

  • 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 https://hotspotssoutheast.com/atcs. The edit is in the .htaccess file but it needs to be restarted or something? Not sure. Thanks.

  • Hi,

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

    e.g.:

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

    the above urls should be accessed without the contextpath
    test.hostname.com/page1
    test.hostname.com/page2?content=1

    Can anybody help me to figure this out?

     

     

     

    • 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.

  • 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 

  • 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.

    • 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.

  • 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

  • Thank you Arnel,

    I found that code in .htaccess file

    # BEGIN WordPress

    <IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /pagalparrot/

    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /pagalparrot/index.php [L]

    </IfModule>

    # END WordPress

    # BEGIN WordPress

    <IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /pagalparrot/

    RewriteRule ^index\.php$ - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /pagalparrot/index.php [L]

    RewriteCond %{HTTP_HOST} ^https://www.pagalparrot.com/%postname% [NC]

    RewriteRule ^(.*)$ https://www.pagalparrot.com/%postname%.html/$1 [L,R=301,NC]

    </IfModule>

    # END WordPress

    or

    # BEGIN WordPress

    <IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteBase /pagalparrot/

    RewriteCond %{HTTP_HOST} ^https://www.pagalparrot.com/%postname% [NC]

    RewriteRule ^(.*)$ https://www.pagalparrot.com/%postname%.html/$1 [L,R=301,NC]

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule . /pagalparrot/index.php [L]

    </IfModule>

    # END WordPress

    then website showing me 500 error šŸ™

    I’m not hard code developer. so please help me with orignal code.

    Best Regards

    Ajay

Was this article helpful? Let us know!