What is an .htaccess Redirect?
An .htaccess file is a hidden Apache web server configuration file placed in your site's root directory. Among many uses, it can redirect visitors from one URL to another — permanently (301) or temporarily (302) — without changing anything in your PHP code or CMS.
301 vs 302 Redirects
- 301 (Permanent Redirect): The resource has permanently moved to a new URL. Search engines transfer ~90–99% of the original URL's ranking power (link equity) to the new URL. Use for: site migrations, URL restructuring, domain changes.
- 302 (Temporary Redirect): The resource has temporarily moved. Search engines keep the original URL indexed. Use for: A/B testing, maintenance pages, seasonal campaigns.
Basic .htaccess Redirect Syntax
To redirect a single page:
Redirect 301 /old-page.html https://yoursite.com/new-page/
To redirect an entire domain (www → non-www):
- Use
RewriteEngine OnwithRewriteCondandRewriteRuledirectives.
How to Generate .htaccess Redirects
.htaccess file.Common .htaccess Redirect Use Cases
- HTTP → HTTPS (force SSL)
- www → non-www (or vice versa) for canonical URLs
- Old domain → new domain after a rebrand
- Renamed pages after a site restructure
- Trailing slash enforcement
FAQ
Does .htaccess work on Nginx or IIS servers?
.htaccess is Apache-specific. Nginx uses its own configuration syntax in nginx.conf, and IIS uses web.config. If you're on Nginx hosting, our generator notes won't apply directly.
How do I check if my redirect is working?
Use a free redirect checker tool or browser developer tools → Network tab. Look for a 301 or 302 status code when visiting the old URL.