A 301 redirect is a crucial tool in website management, helping guarantee smooth changes between pages while preserving SEO rankings. Whether changing your website’s URL structure, migrating to a new domain, or fixing broken links, a 301 redirect via the .htaccess file is one of the most efficient ways to handle these changes. It’s also a very powerful method and, in most cases, will offer more flexibility in how you define your redirect.

With increased flexibility comes an increased risk of error, so proceed with caution. Of course, if at any point you feel out of your depth, you might want to consider contacting a website development agency for help. At Fhoke, we’ve specialised in WordPress since 2008, with 90% of our yearly builds on the platform, so if you’re contacting us for help, you know you’ve come to the right place.

What is the .htaccess file?

The .htaccess file is a configuration file used by Apache servers to control website behaviour, including redirects. You can edit it via cPanel, FTP, via a file manager, a plugin, or if you have the experience, directly on the server via SSH terminal.

Key things to note:

  • if your website is built using a different type of web server or is enterprise hosted, then you might not be able to redirect using .htaccess – the file, if present, could simply be ignored. For example, we encountered one situation where a website was hosted using Apache on Microsoft Azure, and the only way to redirect non-www to www was via Azure Front Door. However, for most typical Wordpress installs built using the very popular LAMP framework (Linux, Apache, MySQL, PHP), the .htaccess file will be present and will be an effective way to set up your redirect.  
  • Apache can be used with many different overlaying website technologies and can still work as an effective method even if your website is not built using Wordpress. If you’re unsure, you can check what technologies your website has been built in using one of the many online tools available, such as Built With, Wappalyzer or Site Checker. 
  • You should only use .htaccess method when you don’t have access to the main server configuration file. The higher up the chain you can go with your redirect instruction, the faster an more efficient the executed redirect will be! 

.htaccess Syntax

The .htaccess file utilises regular expressions (regex) to match patterns and process redirect rules efficiently. This allows for dynamic URL redirection rather than manually specifying each individual redirect, as you might do via a plugin. Regex enables .htaccess to capture parts of a URL, modify them, and apply redirection rules based on flexible conditions.

This rest of this guide will walk you through what a 301 redirect is, when to use it, and how to set it up correctly in .htaccess to avoid SEO pitfalls and ensure a seamless user experience.

Bryanston School WordPress Website Design
Bryanston School, a WordPress Website designed by Fhoke, went through a 10,000+ redirect and SEO exercise.

Understanding 301 Redirects

What is a 301 Redirect?

A 301 redirect is a permanent redirect from one URL to another. It tells search engines and browsers that the original page has permanently moved and, when used correctly, will transfer page rank and link equity to the new URL.

How Does a 301 Redirect Work?

When a browser or search engine requests a webpage that has a 301 redirect, the server responds with a 301 Moved Permanently HTTP status code. This tells search engines and users that the content has been permanently moved to a new location. The browser then automatically loads the new URL, and search engines update their indexes accordingly.

Why Use a 301 Redirect?

A 301 redirect is beneficial for both SEO and user experience because:

  • It preserves SEO rankings by transferring link equity from the old page to the new one.
  • It prevents broken links and ensures users find the correct content.
  • It improves site structure by consolidating duplicate content or restructuring URLs.
  • It enhances security by forcing HTTPS if your site has migrated from HTTP.
  • It helps with domain migration by directing users from an old domain to a new one without losing search traffic.

However, it’s not the only type of redirect method and depending on what you are redirecting, you might opt for another redirect type. 

In all of the following methods, page rank is passed from the old URL to the new URL, however it’s unclear how search engineers deal with 307 or 308 redirects and if you are permanently moving content, you should use the tried and tested method of 301redirect.

Types of Redirects and Their Purpose

Redirect TypePurposeSEO Impact
301 RedirectPermanent redirectCan change the request method from POST to GETPage rank is passed to the new URL
302 RedirectTemporary redirectCan cause an aging delay, where Google continues to rank the old article. Page rank is passed to the new URL
307 RedirectTemporary redirect (preserves request method)Similar to 302, but ensures request method (GET or POST) remains unchangedPage rank is passed to the new URL
308 RedirectPermanent redirect (preserves request method)Similar to 301 but maintains the original request method.Page rank is passed to the new URL

A 301 redirect is ideal for long-term changes, while 302 and 307 redirects are better for temporary moves. A 308 redirect is a stricter version of a 301 redirect that ensures the request method remains unchanged.

When to Use a 301 Redirect

A 301 redirect is essential in various scenarios, including:

  • Changing URL structures – If you’re renaming pages or directories, a 301 redirect ensures old links continue to work while preserving SEO rankings.
  • Migrating to a new domain – Moving your website to a new domain without a 301 redirect can result in lost traffic and rankings. A properly implemented redirect tells search engines to transfer SEO value to the new domain.
  • Redirecting deleted or outdated pages – If you’ve removed or consolidated pages, redirecting users to relevant content helps avoid 404 errors and improves user experience.
  • Enforcing HTTPS for security – Redirecting all HTTP requests to HTTPS ensures encryption, improves security, and boosts SEO rankings since Google favours secure websites.
  • Handling www vs. non-www versions for consistency – To avoid duplicate content issues, it’s important to standardise URLs by redirecting all traffic to either www or non-www.
  • Merging duplicate content – If you have multiple URLs serving the same content, such as product pages with similar variations, redirecting them to a single canonical version helps prevent SEO dilution.
  • Rebranding or restructuring your website – If you’ve changed your business name, restructured your site’s content, or redesigned your site with new URLs, 301 redirects prevent broken links and help retain search rankings.
  • Fixing broken inbound links – If other websites have linked to outdated pages on your site, setting up a 301 redirect ensures users are directed to the correct, updated content instead of encountering a 404 error.
  • Redirecting old blog posts to updated versions – If you’ve created a more comprehensive or updated version of an existing blog post, redirecting the old post to the new one helps consolidate traffic and link equity.
  • Optimising URLs for better readability and SEO – If you’ve adjusted URLs to remove unnecessary words or improve keyword targeting, a 301 redirect ensures users and search engines can still access the new, cleaner URLs.

By strategically implementing 301 redirects, you can maintain traffic, preserve search rankings, and improve the overall user experience without negatively impacting your site’s SEO.

Energising Futures and educational resource for the UK curriculum from BP by Fhoke
Energising Futures is an educational resource for the UK curriculum from BP by Fhoke. We moved them from an old URL to a new URL including over 10,000 page and resource redirects.

How to Set Up a 301 Redirect Using .htaccess

The .htaccess file is a powerful configuration file that controls various aspects of your website, including redirects, security settings, and performance optimisations. However, even a small mistake in the .htaccess file can break your website, leading to errors such as the dreaded “500 Internal Server Error.” Incorrect syntax, conflicting rules, or improperly structured redirects can cause endless redirect loops, slow site performance, or even make your website completely inaccessible. To avoid issues, always create a backup of your .htaccess file before making changes, test your redirects carefully, and use online syntax checkers to verify your modifications. 

If you’re unsure, consider consulting a WordPress Agency like ours or using a WordPress plugin to handle redirects safely. At Fhoke, we advocate the use of Yoast SEO Pro, a plugin that controls the SEO of your site, including their Redirect Manager tool that:

  • Redirects users and search engines from old URLs to new ones
  • Automatically creates redirects when you move or delete pages
  • Prevents dead-ends and 404 errors
  • Scales with REGEX rules, as well as importing and exporting

Regex Basics in .htaccess

Regex provides a way to define patterns for matching URLs. Some common regex symbols used in .htaccess include:

SymbolMeaning
^Matches the beginning of a string
$Matches the end of a string
.Matches any single character
*Matches zero or more occurrences of the previous character
+Matches one or more occurrences of the previous character
?Matches zero or one occurrence of the previous character
()Groups characters together as a single unit
\dMatches any digit (0-9)
\wMatches any word character (letters, digits, underscores)
\sMatches any whitespace character

Basic 301 Redirect Syntax

Redirecting a single page to a new URL:

Redirect 301 /oldpage.html /newpage.html

Redirect an Entire Website to a New Domain

Redirect 301 / https://newdomain.com/

This will forward all pages from the old domain to the corresponding pages on the new domain.

Redirect a Single Page to Another URL

Redirect 301 /old-page.html https://example.com/new-page.html

Redirect a Directory to a New Location

Redirect 301 /old-directory/ https://example.com/new-directory/

Redirect All Pages from an Old Domain to a New Domain

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ https://newsite.com/$1 [L,R=301,NC]

Forcing HTTPS (HTTP to HTTPS Redirect)

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Redirecting from www to non-www (or vice versa)

Redirecting www to non-www:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

Redirecting non-www to www:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

Broken Redirects

  • Cause: Incorrect syntax, improper path definitions, or missing permissions for the .htaccess file can cause redirects to fail.
  • Solution: Ensure that the .htaccess file is located in the correct directory and has proper permissions (644 or 755). Verify that redirects follow the correct syntax and test across different browsers.

Mixed Content Issues

  • Cause: This occurs when a website has been redirected to HTTPS, but some assets (images, scripts, or stylesheets) are still being loaded over HTTP.
  • Solution: Update all internal links, media sources, and third-party scripts to use HTTPS. Implement a Content Security Policy (CSP) to enforce HTTPS loading.

Redirect Chain Issues

  • Cause: When multiple redirects are chained together (e.g., Page A → Page B → Page C), it slows down page loading and negatively impacts SEO.
  • Solution: Consolidate redirects by updating old references to point directly to the final destination (Page A → Page C). Use Google Search Console to identify redirect chains and fix them.

Redirect Not Working in Some Browsers

  • Cause: Some browsers aggressively cache redirects, making it seem like they aren’t functioning properly after updates.
  • Solution: Clear browser cache or test in an incognito window. You can also force a redirect update by adding a query string (e.g., https://example.com/?updatedredirect).

Redirects Causing 500 Internal Server Errors

  • Cause: A syntax error in .htaccess, such as missing spaces or incorrect rewrite rules, can break the server.
  • Solution: Temporarily disable .htaccess by renaming it, then test each rule one by one. Use Apache error logs to identify specific errors.

Redirects Not Passing Link Equity Properly

  • Cause: Using 302 (temporary) redirects instead of 301 (permanent) redirects prevents SEO ranking transfer.
  • Solution: Always use 301 redirects for permanent URL changes to ensure SEO benefits are maintained.

By addressing these common redirect issues proactively, you can prevent downtime, improve user experience, and ensure your site’s SEO remains intact.

Alternative Methods to Redirect Pages

While .htaccess is a powerful way to set up redirects, there are other methods available that can be more user-friendly or better suited to certain environments. These methods include WordPress plugins, cPanel’s Redirect Tool, and server-level redirects for Apache, NGINX, and Cloudflare.

Yoast SEO
Yoast SEO is a great WordPress tool for managing SEO and page redirects. We’re mega fans.

1. WordPress Plugins (e.g., Redirection, Yoast SEO)

For WordPress users, redirect plugins provide an easy way to manage 301 redirects without modifying .htaccess manually. Some of the most popular WordPress redirect plugins include:

  • Redirection Plugin – One of the most widely used plugins for managing redirects. It allows users to create 301, 302, and 307 redirects through an intuitive interface, track 404 errors, and log redirect activity.
  • Yoast SEO Premium – This popular SEO plugin includes a redirect manager that helps set up 301 redirects when a URL is changed. It also allows users to create manual redirects without modifying .htaccess.
  • Rank Math SEO – Provides an integrated redirect manager that lets users handle redirects directly within the WordPress dashboard.

Pros of Using WordPress Plugins:

  • No need to edit .htaccess manually – the plugin will do this for you.
  • Provides a user-friendly interface.
  • Includes logging and tracking features to monitor redirects.
  • Helps manage 404 errors and broken links effectively.

Cons:

  • It can increase website load time due to extra database queries.
  • It may not work on non-WordPress websites.
  • Some advanced features require premium versions.

2. cPanel Redirect Tool (For Non-Technical Users)

Many web hosts using cPanel provide a built-in Redirects tool that allows users to set up redirects without touching .htaccess. This is ideal for users who are unfamiliar with coding but still need a quick way to implement 301 redirects.

How to Set Up a Redirect in cPanel:

  1. Log in to your cPanel account.
  2. Navigate to the Redirects section (under Domains).
  3. Choose the Redirect Type (301 Permanent or 302 Temporary).
  4. Select the domain and enter the old URL and the new destination URL.
  5. Click Add Redirect to save the changes.

Pros of Using cPanel Redirects:

  • Easy to use with a graphical interface.
  • No need for coding or .htaccess modifications.
  • Works at the server level, making it efficient.

Cons:

  • It is not as flexible as .htaccess or server-level redirects.
  • Limited customisation options.
  • Some web hosts may not provide cPanel or may restrict access to redirect settings.

3. Server-Level Redirects (NGINX, Apache, Cloudflare)

For advanced users managing their own servers, implementing redirects at the server level can be a powerful and efficient method. The process varies depending on the server type.

Apache Server Redirects (Using Virtual Hosts)

If you manage an Apache server, you can set up redirects in the virtual host configuration file instead of .htaccess. This method is more efficient as .htaccess requires directory-level processing.

Example: Redirecting an Old Domain to a New Domain in Apache Configuration:

<VirtualHost *:80>
    ServerName olddomain.com
    Redirect 301 / https://newdomain.com/
</VirtualHost>

NGINX Redirects (Faster Than .htaccess)

NGINX does not use .htaccess, so redirects must be configured in the server block.

Example: Redirecting HTTP to HTTPS in NGINX:

server {
    listen 80;
    server_name example.com;
    return 301 https://example.com$request_uri;
}

Example: Redirecting an Old URL to a New One in NGINX:

server {
    rewrite ^/old-page$ /new-page permanent;
}
Cloudflare Website
Cloudflare is more than just about security.

Cloudflare Page Rules (For Managed Redirects)

Cloudflare provides Page Rules, which allow users to set up URL redirects at the DNS level without modifying .htaccess or the server.

Example: Redirecting a Non-WWW to WWW URL in Cloudflare:

  1. Log in to Cloudflare.
  2. Go to Page Rules.
  3. Create a new rule with a pattern, such as example.com/*.
  4. Choose Forwarding URL (301 Permanent Redirect).
  5. Enter the destination URL (https://www.example.com/$1).
  6. Save the rule.

Pros of Using Server-Level Redirects (NGINX, Apache, Cloudflare):

  • More efficient than .htaccess redirects.
  • Suitable for high-traffic websites.
  • Cloudflare’s DNS-level redirects reduce server load.

Cons:

  • Requires server access and technical knowledge.
  • Misconfigurations can bring down the entire website.
  • Changes may take time to propagate, especially with Cloudflare.

Conclusion and Best Practices

301 redirects are essential for maintaining SEO, improving user experience, and ensuring a smooth transition when making changes to your website’s structure. 

The best redirect method depends on your technical expertise and hosting environment:

  • If you use WordPress, a plugin like Redirection or Yoast SEO is the easiest solution.
  • If you have cPanel access, the cPanel Redirect Tool provides a quick, code-free solution.
  • If you’re managing a dedicated or VPS server, using NGINX, Apache virtual hosts, or Cloudflare is the most efficient way to implement redirects.

Always test your redirects, keep .htaccess clean, and use 301 redirects strategically to avoid broken links and SEO pitfalls.

Regardless of the method you choose, always test your redirects to ensure they are working properly and do not negatively impact SEO. Above all, and whichever method you choose, always ensure that you provide your users with the greatest possible user experience and maintain as much page authority as possible. 

Need help setting up redirects using .htaccess or via another method? Give us a shout and one of our Wordpress experts will be able to help you.