How to Set Up a 301 Redirect in .htaccess

301 Permanent Redirects Title Image

If you’re a website owner or administrator, you probably know how important it is to maintain a smooth and seamless user experience on your site. However, there are times when you need to make changes to your website’s structure, reorganize content, or even change domain names. When these changes occur, it’s crucial to ensure that your visitors are seamlessly redirected to the new locations, and this is where 301 redirects come into play.

A 301 redirect instructs web browsers and search engines to permanently redirect users from one URL to another. Whether you’re moving a page, changing your website’s structure, or migrating to a new domain, using a 301 permanent redirect is essential to preserve your website’s SEO ranking, maintain user trust, and ensure a smooth transition for your audience.

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

When would it be necessary to 301 redirect?

301 redirects are a crucial tool for maintaining a website’s user experience, SEO, and overall functionality. Here are some common reasons why website owners use 301 redirects:

  • Changing URL Structure:
    When you reorganize the structure of your website, such as renaming folders or pages, you’ll need 301 redirects to ensure that visitors can still find the content they’re looking for. Without redirects, they may encounter 404 errors.
  • Migrating to a New Domain:
    If you’re changing your domain name or moving your website to a new domain, 301 redirects are essential to seamlessly transfer your old website’s traffic to the new one. This helps maintain your SEO rankings and ensures visitors find your new website.
  • Eliminating Outdated or Unused Pages:
    When you delete or retire pages on your website, setting up 301 redirects can guide users to relevant or updated content instead of encountering 404 errors.
  • Handling Trailing Slashes:
    Consistency in URL structure is important for SEO. If your website URLs have inconsistent trailing slashes (e.g., “example.com/page” vs. “example.com/page/”), 301 redirects can be used to enforce a preferred URL format.
  • Protocol Change:
    If you’re switching from HTTP to HTTPS for improved security, you should set up 301 redirects to ensure that visitors and search engines access the secure version of your site.
  • Managing Affiliate or Marketing Campaigns:
    If you’re running marketing campaigns with unique tracking URLs or affiliate links, 301 redirects can be used to redirect these links to specific landing pages or offers.
  • Fixing Canonicalization Issues:
    To resolve issues related to duplicate content caused by multiple versions of URLs (e.g., with or without “www”), 301 redirects can be employed to specify the canonical version of the URL.

Experience the Power of a Dedicated Server

Know you will always be able to reach your customers when you need to with reliable and secure Dedicated Hosting. Get industry-leading hardware at an affordable dedicated server price.

check markDDoS Protection check markFree Backup Storage check mark100 cPanel Licenses check markManaged Server

Dedicated Servers

Creating 301 Redirects: .htaccess vs. cPanel

When it comes to setting up 301 redirects on your website, you have two primary methods to choose from: editing your .htaccess file directly or using cPanel’s built-in redirection tools.

Editing .htaccess Directly:

Editing your .htaccess file directly provides you with full control over your redirects. You can implement complex rules and handle specific cases precisely. It operates at the server level, which can be more efficient, and it doesn’t rely on a control panel or third-party tools. However, it requires technical knowledge, and mistakes in the .htaccess file can lead to site errors or downtime.

Using cPanel:

cPanel offers a user-friendly interface for managing redirects, making it accessible even to those with limited technical expertise. It’s quick for simple redirects and provides visual feedback to help you understand the rules you’re setting up. However, it may lack the flexibility needed for complex redirect scenarios, and its availability depends on your hosting provider.

Choosing between these methods depends on your specific needs and technical comfort level. Use .htaccess for complex requirements and precise control, especially if you’re experienced with server configurations. Opt for cPanel if you prefer an easy, visual solution for basic redirects, or if you’re a beginner. In many cases, having a basic understanding of both methods can be beneficial for various redirect scenarios. Regardless of your choice, setting up 301 redirects is crucial for maintaining your website’s SEO ranking and ensuring a smooth user experience during changes and migrations.

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

.htaccess redirect to another 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./$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.

Redirect vs. RedirectMatch

Up to this point, we have talked about the Redirect directive as a powerful tool for creating 301 redirects in your .htaccess file. However, it’s important to be aware that there is another directive available – RedirectMatch. These two directives serve distinct purposes and offer different levels of control when it comes to managing your website’s redirects. In this section, we will delve into the differences between Redirect and RedirectMatch to help you choose the right one for your specific redirect needs.

Redirect Directive

The Redirect directive is a simple and straightforward way to create 301 redirects. It’s primarily used for redirecting entire directories or individual URLs. Here’s a breakdown of its characteristics:

  • Usage: The Redirect directive is ideal when you want to redirect one URL to another with a one-to-one mapping, such as redirecting an old page to a new page.
  • Pattern Matching: It performs exact matches, meaning the source URL must precisely match the pattern specified. There’s no support for regular expressions, making it less flexible for complex redirect scenarios.

Example:

Redirect 301 /old-page.html /new-page.html

RedirectMatch Directive

The RedirectMatch directive offers more advanced control over your redirects, as it allows the use of regular expressions to define redirect patterns. Here are its key characteristics:

  • Usage: RedirectMatch is suitable for scenarios where you need more flexibility in defining source URLs to redirect. It’s particularly useful when dealing with dynamic URLs or patterns of URLs.
  • Pattern Matching: It supports regular expressions, enabling you to match a range of URLs that follow a specific pattern. This flexibility allows for more complex and dynamic redirects.

Example:

RedirectMatch 301 /category/(.*) /products/$1

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

The Common Typo: 310 Redirect vs. 301 Redirect

It’s not uncommon for users to inadvertently type “310 redirect” when they actually mean “301 redirect.” This might be due to a simple typographical error or a mix-up with numbers. While there is no HTTP status code officially designated as “310,” it’s essential to clarify this common typo to avoid confusion.

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.

InMotion Hosting Contributor
InMotion Hosting Contributor Content Writer

InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals!

More Articles by InMotion Hosting

181 thoughts on “How to Set Up a 301 Redirect in .htaccess

  1. Hi, My website www.couriertrackingz.com is not redireting when i enter IP address. What should i do so it redirects from the ip address

    1. Ensure you are using a dedicated IP address that resolves to the server where you are setting up the redirect. Also, check if there is another .htaccess file it may be inheriting a rule from, or another rule within the same .htaccess file might be interfering with this redirect.

  2. Hi there, please let me ask before I destroy my site-seo strategy, I need to combine two variables, the “www to non www” and the “remove file extension .php to an slash end”. I use WordPress and I need to make a full 301 redirect to apply to all the content: https://www.domain.com/category/post-name.html to https://domain.com/post-name/

  3. hi
    I want the following addresses in WordPress :

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

    be directed to the previous lesson :

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

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

  4. 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]

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

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

  6. 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 :(((

    1. 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]

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

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

  8. 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?

  9. 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??

  10. 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?

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

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

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

  12. 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? 

    1. 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!

  13. 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!

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

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

     

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

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

    is it posible with .htaccess?? any idea?

  16. 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?

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

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

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

  18. 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,

  19. 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,

     

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

  20. 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!

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

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

  22. 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?

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

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

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

  24. 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?

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

  25. 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 !!!

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

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

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

  27. 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!!

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

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

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

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

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

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

     

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

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

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

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

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

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

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

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

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

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

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

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

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

  38. 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]

  39. Hi

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

    Thanks

     

  40. Excellent information,

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

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

    1. 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?

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

    1. 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!

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

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

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

  45. 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?

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

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

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

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

  48. 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!

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

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

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

    Browser address field show : www.new.com

    Thank you !

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

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

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

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

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

  53. 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!

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

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

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

      Thank you,
      John-Paul

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

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

  56. 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! 

    1. This link may help you:

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

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

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

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

  58. 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!

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

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

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

  60. 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!

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

  62. 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?

     

     

     

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

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

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

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

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

  66. 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? Join the conversation!

Server Madness Sale
Score Big with Savings up to 99% Off

X