Ensuring that your website’s URLs are displaying and operating correctly is imperative as broken links and misdirected traffic can have a serious negative effect on both user experience and SEO. When moving URLs (websites, pages, posts and other content types) from an original to a new source, redirection is vital for steering both site viewers and search engines in the right direction.
In the event that no redirect has been set up for a web element (site, page or post), your site user will be met with an error message while browsing your site. They will more than likely leave your website, and possibly not return. In a similar vein, a search engine will also have no context over which web element to return in a search query.
Note: As best practice, it’s not advised to update and move URLs haphazardly. Redirects should only be set up when absolutely necessary.
3XX: The Different Types of Redirects
The series of numeric codes are HTTP response status codes, and they signal a redirect of sorts. There are a vast number of HTTP response codes, the redirection specific codes consist of three digits and are prefixed with the number 3. If you ever stumble across ‘3XX’ or ‘30X’ when reading about websites, servers and such, it’s more than likely referring to one of the several HTTP response status codes. Each one of these codes is used for different redirection tactics and have different properties. Over time, and with the version update from HTTP/1.0 to HTTP/1.1, these response codes have evolved and split in order to serve a myriad of different purposes (largely taking browser caching as well as request methods POST / GET into account). At present, there are nine redirection status codes (300 – 308).
Without delving into too much detail about the redirect codes, the most important ones are 301 and 302. These have long been the most trusted methods for moving both permanent and temporary URLs respectively. Redirect codes 303 and 307 (temporary) and 308 (permanent) carry significance in their own regard, but not for the purpose of this post, and should only be used with finite knowledge in relation to the code-specific request methods.
What is a 301 Redirect?
Use a 301 redirect if:
- You would like to move your web domain.
- You would like to steer traffic to a new website, page or post from the original source.
- There is a broken URL on your website.
What is a 302 Redirect?
Use a 302 redirect if:
- You are updating a specific web page and want to divert traffic to a new page temporarily.
- You are split testing either design, content or functional aspects (often for client decision and approval).
- You are setting up an online campaign or landing page.
Despite the number of temporary redirects, the 302 is the most widely accepted option as it provides compatibility for browsers that don’t support HTTP/1.1, whereas 303 and 307 are used explicitly for HTTP/1.1 browsers.
How to Set Up a 301 Redirect Using the .htaccess File
Once a new WordPress installation is complete, a file – .htaccess – is, in most cases, automatically added to the root folder of a website. On some occasions, there is no .htaccess file, but one can easily be created by using a text editor or IDE (Brackets or Sublime) and then transferred to the root folder via FTP.
The .htaccess file gets read before the index.php file (which begins to load the full WordPress file package to display a website). In a very generalized sense, the .htaccess file is a config file that is somewhat predominantly focused on the functions of the server and can handle a series of requests including rewrites for redirects.
Remember to back up this file before making any changes. The code in the .htaccess file is extremely sensitive, and one incorrect character can throw an entire website off.
To edit your .htaccess file you will need to login to your server using an FTP client (such as FileZilla or CyberDuck). Some hosts allow for onsite file editing via the File Manager (or similarly named) console. Once you have located the .htaccess file in the root folder of your website, the file should present content that looks like this:
# BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress
301 Redirects for Pages or Posts
# BEGIN 301 Redirects Redirect 301 /old-page-name/ https://www.website.com/new-page-name/ # END 301 Redirects
# BEGIN 301 Redirects Redirect 301 /old-page/ https://www.website.com/new-page/ Redirect 301 /old-page-2/ https://www.website.com/new-page-2/ Redirect 301 /old-post/ https://www.website.com/new-post/ # END 301 Redirects
301 Redirects for Domains
RewriteEngine On RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ RewriteRule (.*)$ https://www.newdomain.com/$1 [R=301,L]
302 Redirects for Pages or Posts
# BEGIN 302 Redirects Redirect 302 /old-post/ https://www.yourwebsite.com/new-post/ # END 302 Redirects
Set up Redirection Using a Plugin
- Quick Page/Post Redirect Plugin
- Redirection
- Safe Redirect Manager (Multisite compatible)
- Simple 301 Redirects
- Yoast SEO Premium (incudes Redirect Manager)
Continuing the trend of redirection, this blog post will be followed with a post that both explains the 404 HTTP response status and includes a short tutorial on how to set up a 404 page for your Divi website.
Thanks for reading!
Would this be the preferred method when converting a site from HTTP to HTTPS? Edit the .htaccess file to 301 all the http requests to new http?
Hello, you should not need to use redirects for adding SSL…please take a look at the process in this article https://designmodo.com/wordpress-http/
You may encounter problems with some of your content such as images using http, but there are some great plugins out there to assist with this: https://wordpress.org/plugins/really-simple-ssl/
Nice summary, but these are relatively simple redirects. I am always struggling with the more complex redirects that happen when variables, category or tag are involved. Like when you have a url that looks like this (to be honest, this is from an Avada website, I haven’t seen Divi generate this)
– https://www.mydomain.com/category/mypage/?portfolioCats=57%2C33%2C34%2C37%2C36%2C40
Or when you have url’s with variables like this:
– https://mydomain.com/?p=123
– https://mydomain.com/?author=3
– https://mydomain.com/?cat=3
Or url’s that contain a category/tag and you want to move the entire category/tag to another one
– https://mydomain.com/mycategory/mypage/
– https://mydomain.com/mytag/mypage/
Hopefully it’s something you can add!
Thanks
JP
Just what I needed this morning. Thanks guys.
Very helpful summary. Thanks!