When a page on your website moves or no longer exists, you need a reliable way to guide users and search engines to its new location. Using the .htaccess file to redirect a page is a powerful server-side solution that maintains user experience and preserves your SEO value. This guide provides clear htaccess redirect examples to help you control traffic effectively.
Table of Contents
What Is an .htaccess Redirect
An .htaccess redirect is a rule you place in your website’s .htaccess configuration file that automatically sends visitors and search engine bots from one URL to another. This is essential for website maintenance, redesigns, or when you consolidate content. Properly implementing redirects ensures you do not lose valuable traffic to “404 Not Found” errors and that search engines transfer authority from the old page to the new one. The impact of web hosting on SEO is significant, and managing redirects correctly is a key part of technical SEO.
Before You Begin Locating Your .htaccess File
The .htaccess file is a powerful configuration file used on web servers running the Apache Web Server software. Before adding any rules, you must locate and open it. You can typically find it in the root directory of your website (often `public_html`). You may need to enable “Show Hidden Files” in your file manager or FTP client, as files starting with a dot are often hidden by default. Always create a backup of your .htaccess file before making changes. A small syntax error can make your entire website inaccessible.
How to Redirect a Page Using .htaccess Examples
Here are the most common scenarios for redirecting URLs. Add these code snippets to your .htaccess file. Ensure that `RewriteEngine on` is present once at the top of your file before any redirect or rewrite rules.
Redirect a Page to Another Page on the Same Site
To redirect an old page to a new page within your website, use the `Redirect 301` directive. This command tells browsers and search engines that the page has moved permanently.
RewriteEngine on
Redirect 301 /oldpage.html /newpage.html
Now, anyone visiting `yourdomain.com/oldpage.html` will be automatically sent to `yourdomain.com/newpage.html`.
Redirect a Page to an External Website
If you need to point a specific page to a completely different domain, the process is very similar. Just use the full URL of the destination as the target.
RewriteEngine on
Redirect 301 /mypage.html http://example.com/
This rule is useful if you have moved a specific piece of content to a new home on another website.
Redirect an Entire Directory
Sometimes you need to redirect all files within a folder to a new location. This rule efficiently handles that without needing to list every single page.
RewriteEngine on
Redirect 301 /old-directory/ http://yourdomain.com/new-directory/
This ensures that any link pointing to a file inside `/old-directory/` will be correctly forwarded to the corresponding location in `/new-directory/`.
Understanding Permanent vs Temporary Redirects
The examples above use `Redirect 301`, which signifies a permanent move. This is the most common type and is best for SEO as it tells search engines to transfer all the link equity and ranking power to the new URL. However, there is another type.
- 301 Permanent Redirect Use when a page’s location has changed for good. This is the correct choice for most situations.
- 302 Temporary Redirect Use when you are moving a page temporarily, such as during site maintenance or A B testing, and plan to move it back. This tells search engines not to update their index with the new location.
Choosing the right type of redirect is critical for site management. For users who need full control over these configurations, our scalable VPS hosting provides the ideal environment.
Common Mistakes and Troubleshooting
If your redirect is not working, check for these common issues. A small typo can break the rule. Ensure the paths are correct. A relative path like `/oldpage.html` starts from your domain’s root. Finally, be aware of redirect loops, where Page A redirects to Page B, which then redirects back to Page A. This will cause a browser error. If you prefer a graphical interface for these tasks, you can also learn how to redirect a subdomain using cPanel.
Frequently Asked Questions
A 301 redirect is a permanent redirect that passes between 90 to 99 percent of link equity to the new page. It is the recommended method for redirecting URLs for SEO purposes when content has moved permanently.
When implemented correctly, the impact of .htaccess redirects on site speed is negligible. However, having a very large number of complex rules can add a small amount of processing time for the server on each request.
Yes, redirects can also be implemented using other methods, such as through your hosting control panel like cPanel or Plesk, with website plugins (for platforms like WordPress), or directly within your application’s code (for example using PHP or JavaScript).
A syntax error in the .htaccess file can cause a “500 Internal Server Error” and make your website inaccessible. This is why it is crucial to back up the file before you make any edits, so you can quickly restore it if something goes wrong.
You can use a rewrite rule in .htaccess to enforce the WWW version of your domain. This helps avoid duplicate content issues with search engines. The code for this is more complex than a simple redirect and involves using `RewriteCond` and `RewriteRule`.





