If your .htaccess redirect isn’t working, the cause is almost always one of a few specific issues: the file isn’t being read, the syntax is wrong, or the rule is being overridden. This article walks you through the most common causes and the exact steps to diagnose and fix them.
What .htaccess Does and Why Redirects Fail
The .htaccess file is a per-directory configuration file used by Apache web servers. It lets you set rules for the directory it lives in and all subdirectories, without needing to edit the main server configuration. A redirect rule tells the server to send a visitor (or a search engine bot) from one URL to another, either permanently (301) or temporarily (302).
Redirects fail when the server never sees the rule, sees it but rejects it, or sees a conflicting rule first. Understanding which of these is happening is the key to fixing it.
Step 1: Verify the File is Being Read
Before you examine the rule itself, confirm that Apache is even looking at your .htaccess file. Many hosts disable .htaccess by default for performance or security reasons.
- Check if the file exists – Use your hosting file manager or FTP client to look in your site’s root directory (usually
public_htmlorwww). The file name must be exactly.htaccess– no leading dot, no extra extension like.htaccess.txt. - Check if it’s hidden – On many file managers, files starting with a dot are hidden by default. Enable “show hidden filesâ€� in your FTP client or file manager settings.
- Test if it’s being processed – Temporarily add a deliberately broken line at the top, like
ThisIsNotAValidDirective. If the server returns a 500 Internal Server Error, then .htaccess is being read. If the page loads fine, the file is ignored.
If the file isn’t being read, you need to enable it. This is done in your Apache configuration by setting AllowOverride All (or at least AllowOverride FileInfo) for the directory. If you’re on shared hosting, contact your host’s support – they can do this for you.
Step 2: Check the Syntax and Format
Apache is strict about .htaccess syntax. A single typo can cause the whole file to be ignored, or worse, generate a 500 error.
- Use the correct directive – For simple redirects, use
RedirectorRedirectMatch. For more complex rules, useRewriteRule(which requiresRewriteEngine On). Mixing them up is a common mistake. - No spaces around the equals sign – In
RewriteRule, flags like[R=301,L]must have no spaces. InRedirect, the status code and URL are separated by spaces. - Use the correct path – In
Redirect, the path is the URL-path starting with a slash (e.g.,/old-page). InRewriteRule, the pattern is matched against the URL-path, but without the leading slash (e.g.,^old-page$). - Keep the file plain text – Save it as UTF-8 without BOM. Some editors add a BOM that can break the first line.
A common mistake is using Redirect 301 /old-page https://example.com/new-page but forgetting that Redirect matches the beginning of the URL. So /old-page-extra would also redirect. Use RedirectMatch with a regex if you need exact matching.
Step 3: Check for Overriding Rules
If your rule is correct but still not working, another rule might be overriding it. Apache processes .htaccess rules in the order they appear. The first matching rule wins (for RewriteRule) or the last matching Redirect wins (because Redirect is handled by mod_alias, which runs after mod_rewrite).
To avoid conflicts:
- Place your redirect rules at the top of the file, before any other rewrite rules.
- If you have both
RedirectandRewriteRule, be aware that mod_rewrite runs first. If aRewriteRulematches and stops (with theLflag), theRedirectwill never run. - Use the
Lflag inRewriteRuleto stop processing further rules for that request.
Also, check if your hosting provider has a global .htaccess file (often in a higher directory) that might be interfering. You can sometimes see this in your file manager.
Step 4: Enable and Check the Rewrite Module
If you’re using RewriteRule, you need the mod_rewrite module to be enabled. Most hosts enable it by default, but not all.
To test, you can create a simple rule like RewriteRule ^test$ https://example.com/ [R=301,L] and visit yoursite.com/test. If it doesn’t redirect, mod_rewrite is likely off. You can try to enable it by adding RewriteEngine On at the top of your .htaccess (which you should already have). If that doesn’t work, contact your host.
Also, note that some hosts use LiteSpeed or nginx, which have different configuration files. If you’re on nginx, .htaccess is not used at all. Check your hosting control panel to see what server software you’re on.
Step 5: Check for Caching and Browser Issues
Sometimes the redirect works, but your browser or a caching plugin shows the old page. This is especially common with 301 redirects, which browsers cache aggressively.
- Try a hard refresh (Ctrl+F5 or Cmd+Shift+R).
- Test in an incognito/private window.
- Clear your browser cache or use a different browser.
- If you have a caching plugin (like WP Super Cache or W3 Total Cache), clear its cache.
- Use an online redirect checker tool to see what the server actually returns for the URL.
If the tool shows a 301 redirect to the correct URL, then the server is fine – the issue is on your end.
Common Mistakes and How to Avoid Them
- Missing
RewriteEngine On– Without this,RewriteRuledoes nothing. - Wrong file permissions – The .htaccess file should be readable by the web server. Usually 644 is fine, but if you get a 500 error, try 444 or 604.
- Using absolute paths in
RewriteRulepatterns – The pattern matches the URL-path, not the filesystem path. So^/old-page$is wrong (unless you’re in a subdirectory context). - Forgetting the
Rflag – WithoutR,RewriteRuledoes an internal rewrite, not a redirect. The URL stays the same in the browser. - Not escaping special characters – In regex patterns, characters like
.and?are special. Use\.and\?to match them literally.
Frequently Asked Questions
Why does my redirect work for some URLs but not others?
This usually happens when your rule is too specific or too broad. For example, a Redirect on /old will also match /old-page because it matches the beginning. If you want only the exact URL, use RedirectMatch with ^/old$. Conversely, if you have a rule for /old-page but the URL is /old-page/, it might not match because of the trailing slash. Check the exact URL you’re testing.
What’s the difference between 301 and 302 redirects?
A 301 is a permanent redirect – it tells browsers and search engines that the page has moved for good. A 302 is a temporary redirect – it says the page is temporarily at a different location. For SEO, use 301 for permanent moves. If you use 302 for a permanent move, search engines may keep indexing the old URL.
How do I redirect from HTTP to HTTPS?
Add this to your .htaccess file in the root directory:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
This checks if HTTPS is off, and if so, redirects to the HTTPS version of the same URL. Make sure your SSL certificate is installed correctly first.
Why do I get a 500 Internal Server Error after editing .htaccess?
This is almost always a syntax error. Check for missing spaces, extra characters, or an invalid directive. A quick way to find the error is to look at the server error log (often in your hosting control panel under “Error Logs�). The log will show the exact line that caused the problem.
Can I use .htaccess to redirect a subdirectory to another domain?
Yes. For example, to redirect everything under /blog to https://example.com, you can use:
RewriteEngine On RewriteRule ^blog/(.*)$ https://example.com/$1 [R=301,L]
Place this in the .htaccess file in your root directory, not in the /blog directory itself, to avoid recursion issues.
My redirect works in the browser but not in search engines. Why?
Search engines may have cached the old URL. They will eventually re-crawl and see the 301, but it can take time. To speed it up, submit the URL in Google Search Console and request indexing. Also, ensure you’re using a 301 (not 302) for permanent moves, as 302s are often ignored for indexing purposes.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Python Search Highlighting: Snippets & Matches
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km
- Connect Phone to Controller for Cloud Gaming