![301 Permanent Redirects Title Image](https://www.inmotionhosting.com/support/wp-content/uploads/2020/12/301-Permanent-Redirects-1024x538.png)
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.
- When would it be necessary to 301 redirect
- .htaccess vs. cPanel
- Set Up 301 Redirect via .htaccess file
- Set Up 301 Redirect via cPanel
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.
DDoS Protection
Free Backup Storage
100 cPanel Licenses
Managed Server
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.
- Login to your cPanel.
- Under Files, click on File Manager.
- Ensure that Show Hidden Files is selected by clicking Settings on the top right corner of the File Manager.
- Select the Document Root for: option, and choose your domain from the drop-down.
- Right-click on the .htaccess file and select Edit.
- 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.
- You might have a text editor encoding dialog box pop-up, you can simply click on Edit to proceed.
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](/support/images/stories/htaccess/301-redirect/single-file-301-redirect.gif)
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](/support/images/stories/htaccess/301-redirect/single-file-domain-301-redirect.gif)
.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](/support/images/stories/htaccess/301-redirect/full-domain-301-redirect.gif)
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](/support/images/stories/htaccess/301-redirect/force-www-301-redirect.gif)
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](/support/images/stories/htaccess/301-redirect/force-non-www-301-redirect.gif)
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](/support/images/stories/htaccess/301-redirect/file-extension-301-redirect.gif)
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.
- Login to cPanel.
- Click the Redirects button in the Domains section.
- 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.
- Click the next drop-down box and choose the domain you want to redirect.
- For the slash ‘/’ field, enter any folder names (if necessary).
- Enter the address you want to redirect to in the Redirects to section.
- Choose if you want to “Only redirect with www.” “Redirect with or without www.” or “Do Not Redirect www.“
- 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.
- Click Add when finished.
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.
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
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.
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/
Since WordPress relies on .htaccess rules, I do not recommend adding rules manually to the file. Instead, I recommend setting up permalinks in your Dashboard, then using a 301 redirect plugin to permanently forward any old URLs to the new ones. This will automatically add the rules to your .htaccess file in accordance with WordPress rules.
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.
These things work smoothly. Thanks for the update.
You’re welcome! Thanks!
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.
thanks for sharing informative article.
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?
Hi Luciana,
Yes, it should work for what you’re trying to achieve. However, if you run into issues, please contact our live support.
I had tried step by step in inmotionhosting.com. But, how long to see redirection running ?
Hello and thanks for contacting us. The redirect should be immediate unless you have caching set up on the website. I recommend you try this in a private browsing session.
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??
Hello and thanks for asking. You can simply change the redirect URL to /example-page.
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.
live url https://www.proyellowpage.com/search-inventory.php?city=1&keyword=Health&search=
its posible custome url like https://www.proyellowpage.com/1-Health
please help me making url
You will want to have a developer help you with URL “rewrites” not redirects.
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.
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?
Check out this article to learn how to force WWW in .htaccess.
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.
Thank You !!!
Very useful for me
“Permanent 301 Redirect in .htaccess ”
Thank You
Great! I’m glad this worked for you!
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,
You can use the method for redirecting an old domain to a new domain option to do this.
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 recommend using the Redirect Individual Files section’s code as outlined in this article that you are commenting on.
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
I’d like to redirect subdirectory (vb) to a main domain without losing the index in google. Example:
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!!
Just edit your .htaccess file and remove the added rules, or rename your .htaccess file which will disable all rules.
Thank you,
John-Paul
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.
Thanks you so much my site redirect and working perfect now!
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 loop chain on my site please help me https://www.sitesazan.net
What kind of redirect rule did you use? Are you able to delete the rule you added?
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.
Thanks for the question about forcing HTTPS with your redirect code. We do not provide coding support as that is beyond our scope of support, but we do try to provide a direction that helps to give you a solution. You can use this tutorial for forcing the use of HTTPS for further information.
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.
Now I want to redirect from shop.local/shop/en/store to www.shop.local/shop/en/store
You should be able to just redirect the domain to www. All other relative paths should follow.
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]
The syntax looks good, but I advise double-checking with our full guide on forcing www with .htaccess.
Hi
I am unable to fing the .htaccess folder in cPanel. I am trying to force a https connection on my website.
Thanks
If there’s not an .htaccess file in your directory you may need to show hidden files or create one if there’s not one hidden.
Excellent information,
Very useful support to the website redirections up a 301 permanent redirect via htaccess files setup.
nice article 🙂
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.
Can the code above be used for redirecting with https as well?
Yes, it should be the same. You may also want to check out our full guide on using .htaccess to force https.
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
If you want to only use the SSL, you can force https using the .htaccess file. If you are using a CMS such as WordPress, Drupal, Joomla, etc. you should make the change in their admin dashboard.
Thank you,
John-Paul
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.
Great thanks!!! It worked for me!
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
Any recommendations on a good plugin to achieve this?
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
Thanks!
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!
You can set the https right inside your WordPress General settings. This should redirect it for you.
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.
You may need to clear your browser cache. It’s possible content is being saved locally.
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
Yes Prashant, that can be done. Examples are in the post above.
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
Enea, you can edit your .htaccess file to keep everything after the base URL, but still redirect.
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