How to set up a redirect
A URL redirect is a webserver function that sends a user from one URL to another. Redirects commonly take the form of an automated redirect that uses one of a series of status codes defined within the HTTP protocol (301 for most cases).
In other words, this is a server command that specifies when a specific URL is accessed, the browser will automatically access another link that you specified.
The easiest way of setting up a redirect is usually by using third-party plugins. Please refer to our tutorial on installing plugins if you are unsure how to do this: Installing a Plugin Tutorial
One of the easiest to set up and use plugins is called Simple 301 Redirects.
Here is a short video showing how to set up one simple redirect via the plugin mentioned above:
Redirects can also be set up directly via the .htaccess file of your website. If you plan on modifying your .htaccess file, make sure to backup your website files and database before proceeding.
If you’ve already backed up your website, you can start editing the .htaccess file via a FTP client or hosting File Manager interface. The .htaccess file is usually located in the root directory of your WordPress installation:
Once you open the file, it should contain the default WordPress rules and most likely will also include additional commands from third-party services (hosting, plugins etc.)
Usually, htaccess rules are separated with comments at the beginning and end of the htaccess snippet.
Any custom redirect rule should be added ABOVE the WordPress htaccess configuration.
You can review below a few examples of different redirect rules:
301 (Permanent) Redirect: Point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the “mt-example.com” domain:
# This allows you to redirect your entire website to any other domain Redirect 301 / http://example-site.com/
302 (Temporary) Redirect: Point an entire site to a different temporary URL. This is useful for SEO purposes when you have a temporary landing page and plan to switch back to your main landing page at a later date:
# This allows you to redirect your entire website to any other domain Redirect 302 / http://example-site.com/
Redirect index.html to a specific subfolder:
# This allows you to redirect index.html to a specific subfolder Redirect /index.html http://example-site.com/newdirectory/
Redirect an old file to a new file path:
# Redirect old file path to new file path Redirect /olddirectory/oldfile.html http://example-site.com/newdirectory/newfile.html
Redirect to a specific index page:
# Provide Specific Index Page (Set the default handler) DirectoryIndex index.html
If you feel unsure on how to complete the processes described above, it’s best to reach out to your hosting provider for assistance in this matter.