How to Set Up 301 Redirects in WordPress: A Step-By-Step Guide to 4 Methods

Encountering a 404 Page Not Found error is frustrating for visitors and detrimental to website owners. If users keep landing on broken pages, it can significantly hurt your search engine rankings.

Fortunately, there is a clever solution: The 301 Redirect.

What is a 301 Redirect?

Essentially, a 301 redirect tells both website visitors and search engines that a page on your website has permanently moved to a new location. Instead of seeing an error message, anyone trying to visit the old address is automatically sent to the new one. This ensures a smooth user experience and maintains your SEO value.

Here are four methods to set up 301 redirects in WordPress, ranging from beginner-friendly tools to advanced manual coding.


Method 1: Using hPanel (For Hostinger Users)

If you are hosting your WordPress site with Hostinger, this is by far the easiest method.

  1. Log in to your hPanel account.
  2. Navigate to Websites, choose your preferred website, and click Dashboard.
  3. On the left sidebar, find Domains and select Redirects.
  4. Configure the Redirect:
    • Redirect: By default, this is filled with your domain. You can specify a specific path if needed.
    • Redirect To: Choose “URL” or “IP”.
    • Target: Enter the new domain or IP address where you want visitors to go.
  5. Click Create.

The list of existing redirects will appear at the bottom of the page, where you can manage or remove them later.


Method 2: Using the All-In-One SEO (AIOSEO) Plugin

If you prefer using a plugin, All-In-One SEO offers an easy setup.

> Note: The redirect manager feature is typically available only on the plugin’s Premium plan.

  1. Install and Activate the All-In-One SEO plugin. (You can skip the initial setup wizard if you prefer).
  2. Go to the All-In-One SEO menu on the left sidebar of your WordPress dashboard.
  3. Scroll down and click Redirects.
  4. Enter URL Details:
    • Source URL: Enter the old link you want to redirect from.
    • Target URL: Enter the new location you want to redirect to.
  5. Select Redirect Type: Choose 301 Moved Permanently.
  6. Click Add Redirect.

Method 3: Manually Editing the .htaccess File

If you are comfortable writing code, you can edit your site’s .htaccess file. This is a powerful method, but it requires caution.

Warning: Before editing core files, it is highly recommended to create a website backup. A slight typo here can break your site.

Accessing the File

  1. Access your website files using an FTP client or your hosting File Manager.
  2. Open the public_html folder.
  3. Locate and double-click the .htaccess file to edit it.

Scenario A: Redirecting a Single Page

  1. Find the line in the code that says RewriteEngine On.
  2. Add the redirection code below this line.
  3. The code structure usually looks like this: Redirect 301 /old-page-url https://yourdomain.com/new-page-url
  4. Save the file (click the disk icon).

Scenario B: Redirecting an Old Domain to a New Domain

If you are moving your entire website to a new domain, you can use a specific redirection rule.

  1. Locate RewriteEngine On.
  2. Paste the domain redirection rule below it.
  3. Ensure you replace the placeholder text with your actual old domain name and new domain name.
  4. Save the file.

Method 4: Using a PHP Script

This method is best for advanced users who need to manage multiple specific redirects via a script.

  1. Log into your hosting control panel (e.g., hPanel) and go to File Manager.
  2. Open the public_html folder.
  3. Click New File on the sidebar and name it redirects.php.
  4. The new blank file will open automatically.
  5. Paste your PHP redirection code into the file.
    • Note: You will need to replace the specific “Location” part of the code with the new URL you want to redirect to.
  6. You can add multiple blocks of code for different redirects within this file.
  7. Click the disk icon to Save.

How to Test

To ensure the script is working, open your browser and type the address of your script (e.g., yourdomain.com/redirects.php). If it automatically sends you to the destination you defined, you are good to go!


Summary

Whether you prefer a simple interface like hPanel, a WordPress plugin, or manual code editing, setting up 301 redirects is a vital skill for maintaining a healthy website. Always remember to test your redirects immediately after setting them up to ensure your visitors never hit a dead end.

Source

Previous Post Next Post