To create a 301 redirect in .htaccess, open that file in your site's root directory and add the line Redirect 301 /old-url https://yourdomain.com/new-url. In most cases, that single line is all you need.
Below you'll find every common scenario with copy-ready examples so you can set redirects up correctly without hurting your rankings.
What Is a 301 Redirect and Why Does It Matter?
A 301 redirect tells browsers and search engines that a URL has permanently moved. The HTTP 301 status code passes approximately 90–99 % of the original page's link equity (SEO authority) to the new URL.
The three most common use cases are:
- Changing your site's URL structure (e.g., from
/blog/post1to/articles/post1). - Migrating from HTTP to HTTPS.
- Consolidating multiple domains or duplicate pages into one canonical URL.
Without the redirect, visitors land on a 404 error and Google loses track of your indexed content.
How to Open and Edit Your .htaccess File
The .htaccess file lives in your hosting's public root (usually public_html/). You can edit it three ways:
- cPanel → File Manager: navigate to
public_html, enable "Show hidden files," then click.htaccess→ Edit. - FTP client (FileZilla): connect to your server, enable hidden file display (Server → Force showing hidden files), download the file, and edit locally.
- SSH: if your plan supports it, run
nano public_html/.htaccess.
Always download a backup copy before making any changes. A syntax error in .htaccess triggers a 500 error across your entire site.
Basic Syntax: Simple 301 Redirect
Apache provides two built-in ways to redirect inside .htaccess:
Option A — mod_alias (no RewriteEngine needed)
Redirect 301 /old-page.html https://www.yourdomain.com/new-page/
Best for redirecting one or a handful of specific URLs. Does not require mod_rewrite.
Option B — mod_rewrite (more flexible)
RewriteEngine On
RewriteRule ^old-page\.html$ /new-page/ [R=301,L]
Use this when you need pattern matching, regular expressions, or additional conditions with RewriteCond.
Common Use Cases with Examples
1. Redirect HTTP to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This block catches any non-HTTPS visit and redirects it to the secure version. Most hosts add this automatically when you install an SSL certificate, but if not, this code works on any Apache server.
2. Redirect www to non-www (or vice versa)
# www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R=301,L]
Reversing it is as simple as swapping the two domain names. Pick one canonical format and stick with it across your entire site.
3. Redirect an Entire Directory
RewriteEngine On
RewriteRule ^blog/(.*)$ /articles/$1 [R=301,L]
The wildcard (.*) captures everything after /blog/ and appends it to the new path. This is a lifesaver during CMS migrations.
4. Redirect a Whole Domain to Another
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com [NC]
RewriteRule ^(.*)$ https://www.new-domain.com/$1 [R=301,L]
Essential when rebranding or consolidating multiple domains under one primary domain.
Common Mistakes and How to Avoid Them
| Mistake | Cause | Fix |
|---|---|---|
| 500 error after saving | Syntax error in the file | Validate with apachectl configtest or restore your backup |
| Infinite redirect loop | The destination URL re-triggers the same rule | Add RewriteCond %{HTTPS} off or use more specific conditions |
| Redirect not working locally | AllowOverride None in the VirtualHost block |
Change to AllowOverride All in your local server config |
| Google not updating the URLs | Crawl cache (can take weeks) | Submit the updated sitemap in Search Console and use the URL Inspection tool |
If you need help getting your hosting environment configured correctly, elenlace.com offers managed hosting plans with technical support that covers exactly these kinds of tasks.
Key Takeaways
- A 301 redirect is permanent and passes SEO authority from the old URL to the new one.
- Edit
.htaccessvia cPanel, FTP, or SSH — always keep a backup first. - Use
Redirect 301for single URLs andRewriteRule [R=301,L]for patterns and conditions. - The most common scenarios are HTTP→HTTPS, www→non-www, slug changes, and full domain migrations.
- Verify results with the URL Inspection tool in Google Search Console.
Planning a migration to HTTPS or a new domain? The team at elenlace.com can handle the full setup so you don't lose a single ranking point. Also check out our hosting glossary for more technical guides.
FAQ
How long does it take Google to process a 301 redirect?
Google can take anywhere from a few days to several weeks to crawl and update URLs in its index. You can speed things up by submitting an updated sitemap in Google Search Console and using the URL Inspection tool to request crawling of your key pages.
Does a 301 redirect hurt SEO?
When implemented correctly, a 301 redirect preserves 90–99 % of link equity. A 302 (temporary) redirect does not pass authority, so using the wrong status code can genuinely harm your rankings.
Can I add multiple 301 redirects to the same .htaccess file?
Yes. You can add as many Redirect 301 lines or RewriteRule blocks as you need. Apache processes them top to bottom, so order matters when rules might overlap.
What if I don't have access to .htaccess?
If your server runs Nginx instead of Apache, .htaccess does not apply. On Nginx you'll use return 301 directives inside the server block of your virtual host config — which requires SSH or admin-level server access.
Useful resources
Other providers and guides worth comparing: