how to redirect using htaccess

How To Redirect Using htaccess Correctly

We all bookmark pages all the time yet you might try to revisit that URL only to see a 404 page. Fixing this takes less than 10 seconds but requires you to know how to redirect using htaccess correctly.


Every time a user reaches a 404 page, you make them sad! The user experience is less than perfect. And so, it’s worth fixing these issues.


Thankfully, learning how to redirect using htaccess is simple, quick, and effective. So it’s worth knowing how to do it.



3 Reasons to use redirects when deleting a page

Firstly, you can’t just delete a page on a website. You really should try and send that traffic to another relevant page or at worst a category page.


Doing so helps to create a better user experience and could help you convert more website visitors into customers. Hackers might crawl your website looking for multiple cases of 404 pages. They might attack as they believe your website is an easy target.


Secondly, if you have good quality links pointed at that page, which is helping you to build a stronger domain authority and rankings, you’ve just shot yourself in the foot! You can kiss goodbye to them.


With a redirect in place, you can transfer the link strength onto the new page and maintain your search engine rankings.


Thirdly, redirects can help you use your Google crawl budget more effectively. As Google views your website, it will look for pages which it can find (status code 200), have moved (status code 301/302), or have been deleted (status code 404/410) as well as serve errors (status code 500).



How to find these errors?

Screaming Frog

screaming frog 404 errors


You can use a tool like ScreamingFrog (free) to find out the status codes of all your pages.


Google Search Console

Google search console 404 errors


Google Search Console (free) will show you 404 and 500 in an easy to understand way.


SEO Powersuite Website Auditor

seo powersuites website auditor 404


My favorite tool by far is Website Auditor by SEO Powersuite. It’s really powerful and offers you a ton of usable insights on top of finding broken links and showing the status codes of every page. If you don’t yet have this tool, start by reading my review.




Redirect types and usage

Before I show you how to redirect using htaccess and how to check that they’re working, let’s look at a few examples.


Former product

So you have a few products which have been discontinued, and you want to delete their pages. Just go for it? Wrong.


Firstly, consider where the customer intent lies. Do they want support for that product which is answered by another page? Have you decided that product isn’t a fit for your business? or did you find that the product wasn’t profitable under market pressures?


In all of these, you can help the customer in their journey by using a 301 redirect.


If the product doesn’t fit within your current range or wasn’t profitable, it might be best to redirect to the top category page. In both cases, you’re aiming to keep the prospect warm to your current offering.


However, if the product is discontinued but you still provide support, either redirect to a page about product support (you could also build one!) or add who to contact on your FAQ page.


Old pages

We’ve all created pages that we believe targeted a keyword or a cluster, only to find out later that the keyword is super competitive or doesn’t matter our customer’s intent.


In some cases, it’s best to delete and start again and redirect the old page to the new one. You can, of course, keep the old page but rename it and rewrite the content to better match the search intent. Again, you’d want to redirect the old URL to the new.


In-depth content

As we trend toward more long-form content, you can answer a few questions in one post and so you might be able to delete a few pages and replace them with one more in-depth article. Again redirecting and deleting is your best option.



How to redirect

Before we get into how to edit your htaccess file, a warning!


Editing this file can have massive implications for your website.


If you’re going to try editing this file yourself, please make a copy on your hard drive first.


This way if you manage to crash your website, you’ll be able to get it back up and running quickly.


Warning over!


Redirect a website to www

This is the simplest redirect

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


Redirect to HTTPS

If you have an SSL, you’ll want to consider redirecting your website to HTTPS

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


Simple 301 redirect

The most basic and common redirect you’ll need is a 301

Redirect 301 /oldpage.html


Redirect 301 /oldpage.html



A catch-all (most) redirect

As this is quite complex, you’ll want to spend a few minutes thinking before you go gung-ho and crash your website!


If you’re using WordPress, you’ll know if you create more than 10 posts, WordPress automatically starts to create pages with 10 results. If you decided to delete this category, you can’t simply use a 301 redirect as page 2/3/etc will still be indexed by Google and may even be bookmarked.


So you’ll need to use a 301 redirect match to catch all and redirect to a new page. This type is also logic-based, which means you can use /*/ to catch things such as multiple pages etc.


RedirectMatch 301 ^/blog/category/*/




So you’ve copied your current htaccess file into a word doc or notepad file, what’s next? Copy all your old URLs into a new notepad file. Add in the new URLs after the old as well as the redirect code at the start of the line.


Next, you’ll want to add a new redirect to your htaccess file. To check that it works and your website is live, open a private tab in your browser and enter your URL. Use a private window as they don’t cache your settings/cookie/page.


If it works, you’ve done well. Now how to redirect using htaccess! If not, you need to revisit your code, tweak and try again.


Please, add one redirect at a time and keep testing as this makes it’s far easier to find issues!



That’s how to redirect using htaccess!

I hope that enables you to create a better user experience on your business website that should lead to an improvement in conversions. Plus, you’ll also be able to hold on to link juice. And as you now know how to redirect using htaccess, you can ensure your website visitors experience the best!

Last month Izabela saw her search traffic from Google increase by 400% using 3 SEO tips we taught her.

Want the same results? Let's Chat

Want To Drive A Ton Of New Ecommerce Sales?

Join our weekly email for the latest ecommerce digital marketing strategies, tips, and information.