How to redirect a page or website using .htaccess
If a page on your website has moved or no longer exists, visitors who follow an old link will hit a “404 Not Found” error. A redirect solves this by automatically sending anyone who requests the old address to the new one instead.
Redirects are handled by a file called .htaccess, which sits on your hosting account and tells the web server how to respond to certain requests. This guide covers the most common redirect types, where to put the code, and how to check it worked.
Does your hosting support .htaccess? #
The .htaccess file is a feature of the Apache and LiteSpeed web servers, which is what our shared hosting and most of our server plans run. If that is you, everything in this guide applies.
Two setups work differently. Sites running on Nginx ignore .htaccess entirely, and redirects have to be added to the server configuration instead. Sites on Windows hosting use a file called web.config rather than .htaccess. If your site is on either of those, open a support ticket with the old and new addresses and we will set the redirect up for you.
The instructions below use cPanel because that is what most customers have, but .htaccess is not a cPanel feature. If you use a different control panel, or reach your files by FTP or SSH, the file lives in the same place and the code is identical. Only the steps for opening it differ.
Before you start #
Find your .htaccess file. Log in to cPanel, open File Manager, and go to the folder that holds your website. For most accounts this is public_html. If you run more than one website on the account, each add-on domain has its own folder with its own .htaccess file, so make sure you are in the right one.
Turn on hidden files. Any filename beginning with a dot is hidden by default. In File Manager, click Settings in the top right, tick Show Hidden Files (dotfiles), then click Save.
Create the file if it isn’t there. Not every site has one yet. If you don’t see .htaccess in the folder, click + File, name it .htaccess exactly (including the leading dot, and with no .txt on the end), and save.
Make a backup first. Right click the file, choose Copy, and save a copy as something like htaccess-backup.txt before you change anything. A small typo in this file can take your whole site offline, so having the original to restore is worth the thirty seconds.
To edit the file, right click it and choose Edit.
301 or 302: which one to use #
You will see both numbers in redirect code. They mean different things:
- 301 is a permanent redirect. Use this when the old page is never coming back. Search engines will transfer the old page’s ranking value to the new page and update their index over time. This is what you want in almost every case.
- 302 is a temporary redirect. Use this only when the old page really is coming back, for example while you rebuild a page or run a short campaign. Search engines keep the old page in their index and pass no ranking value to the new one.
If you are not sure, use 301.
Redirect one page to another page on the same site #
Add this line to your .htaccess file:
Redirect 301 /oldpage.html /newpage.htmlNow anyone who visits example.com/oldpage.html lands on example.com/newpage.html instead.
Two details matter here. The first path must start with a forward slash and must not include your domain name. The second path is where visitors end up, and because it is on the same site you can write it as a path in the same way.
If the old page sits in a subfolder, include the folder in the path:
Redirect 301 /blog/old-article.html /blog/new-article.htmlRedirect one page to a different website #
When the destination is on another domain, write it out as a full URL including https://:
Redirect 301 /mypage.html https://example.com/If you leave off the https:// part, the server treats it as a path on your own site and the redirect will not go where you expect.
Redirect a whole directory #
To move every page inside a folder, point the folder itself at its new location:
Redirect 301 /old-folder /new-folderThis carries the rest of the address across automatically. A request for example.com/old-folder/page1.html becomes example.com/new-folder/page1.html without you needing a separate line for each page.
Redirect an entire website to a new domain #
If you have rebranded or moved to a new domain, place this in the .htaccess file of the old site:
Redirect 301 / https://newdomain.com/Every page on the old domain will now redirect to the matching page on the new one.
One warning: only do this when the two domains point at separate folders on the server. If both domains are set up to load the same folder, this line sends the site into an endless loop and nothing will load. In that situation you need a different approach, so contact our support team and we will set it up for you.
Do I need the RewriteEngine line? #
No. You may have seen RewriteEngine on written above redirect code elsewhere. That line belongs to a different Apache module (mod_rewrite) and does nothing for the Redirect lines shown in this guide. Including it is harmless, but leaving it out keeps the file cleaner and easier to read later.
Mod_rewrite is a more advanced tool used for pattern-based rules, such as redirecting every URL that contains a particular word. If your redirect is a straight swap of one address for another, the Redirect lines above are the simpler and better option.
Adding more than one redirect #
You can stack as many redirects as you need, one per line:
Redirect 301 /about-us.html /about.html
Redirect 301 /services.html /what-we-do.html
Redirect 301 /old-blog https://blog.example.com/The server reads the file from top to bottom and uses the first rule that matches. Avoid redirecting a page to another page that is itself redirected somewhere else, because chaining redirects slows the site down and can confuse search engines. Always point the old address straight at its final destination.
Lines beginning with # are comments. The server ignores them, so they are useful for leaving notes to yourself:
# Old service pages retired March 2026
Redirect 301 /services.html /what-we-do.htmlTest that it worked #
Save the file, then open the old address in your browser. You should land on the new page, and the address bar should show the new URL rather than the old one.
If nothing seems to change, try again in a private or incognito window. Browsers store 301 redirects aggressively, and once your browser has learned an old rule it will keep using it even after you change the file. A private window ignores that stored copy and shows you the current behaviour.
If something goes wrong #
The site shows a 500 Internal Server Error. This almost always means a typo in the .htaccess file. Check for a missing slash, a missing https://, or a line that has been split in half. If you cannot spot it, restore the backup you made earlier and the site will come straight back.
The redirect doesn’t happen at all. Confirm you edited the .htaccess file in the correct folder. If the site is on an add-on domain, the file in public_html is the wrong one.
The page keeps reloading or times out. You have likely created a loop by redirecting a page to itself, or by redirecting a domain to another domain that loads the same folder. Remove the rule and get in touch with us.
Your CMS overwrote your changes. WordPress and similar platforms manage part of the .htaccess file themselves. Add your redirects above the block marked # BEGIN WordPress, not inside it, or the next permalink change will wipe them out. For WordPress sites, a redirect plugin is often easier to manage than editing the file by hand.
If you get stuck at any point, open a support ticket and include the old and new addresses you are trying to link up. We can apply the redirect for you.
