There are countless reasons why you may want to redirect the user’s browser from one URL to another.
Maybe you’ve redesigned and restructured your website. And now, you want to point users to the updated URLs of the old pages.
Or maybe you rebranded your business and changed the domain name. Hey, your business might even have gotten bought out by a larger competitor, and you are now merging your websites into one.
Well, let’s just say you came to the right place! Read on because we have it all for you:
- We’ll take a closer look at 301 redirects
- And talk about when you should use each of these, especially when it comes to your website’s search engine optimization (SEO)
What Is a 301 Redirect?
A 301 redirect is a server-side HTTP redirect that tells users’ browsers and search engine crawlers that a website, page, or file has permanently moved to a new URL, and that the old URL will no longer be used.
301 redirects can be configured on a server level, in the
httpd.conf configuration file of your Apache web server, or at the directory level, in the
.htaccess file for the root domain, add-on domain, or directory in question.
For performance reasons, it is better to configure 301 redirects in the httpd.conf file of your Apache web server rather than in an
.htaccess file, especially if the structure of your website consists of many folders and is quite complex.
That said, most webmasters are willing to put up with a few added milliseconds in their server’s response time and configure 301 redirects in an
.htaccess file regardless. For them, it’s easier to set up the rules in the dedicated text-based configuration file for the directory that they apply to.
Did you know?
301 redirects are only one type of HTTP redirects. In some cases, it is better to set up a temporary 302 redirection. When in doubt, read our no-B.S. guide to the difference between 301 and 302 redirects.
window.location.href option is best used when you want to take the user to a new page because they clicked a button, a link, or some other interactive UI element. The original URL is saved in the browsing history, and the user can return to the previous page if needed.
window.location.replace option is best if you want to simulate a 301 redirect. The original URL isn’t saved in the browsing history, so the user can’t return to the previous page.
When to Use a 301 Redirect
If you’re restructuring your website, changing the domain name, or merging it with another site, set up a 301 redirect. A 301 redirect is also the one to opt for if you want your website to load only under the HTTPS protocol or with or without
A 301 redirect is also the right way to inform search engine crawlers that the website, page, or file in question has permanently moved to a new URL.
This type of redirect is best from an SEO point of view. After 6 months to 1 year of the 301 redirect being active, Google, Bing, and DuckDuckGo will transfer the old page’s backlink equity and page rank to the new one.
window.location.replace. Use this only as a last resort, as search engine crawlers may not get to the final page and see the new URL.
If you’re restructuring your website, moving to a new domain name, or merging with another website, then the best type of redirect to use is a server-side 301 redirect.
Thanks for reading this far! I hope this helped you decide, and do let me know in the comments if you have any more questions!