SEO Tools February 24, 2025 · ~5 min read

.htaccess Redirect Generator: 301 & 302 Redirects Explained

An .htaccess redirect tells Apache web servers to automatically send visitors from one URL to another. This guide explains 301 vs 302 redirects, how to write redirect rules, and how to generate them instantly.

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.
⚠️ SEO Warning: Using 302 redirects when you mean 301 is one of the most common SEO mistakes. If content has permanently moved, always use 301 to preserve your search rankings.

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 On with RewriteCond and RewriteRule directives.

How to Generate .htaccess Redirects

1Open the .htaccess Redirect Generator tool.
2Select redirect type: 301, 302, www → non-www, HTTP → HTTPS, etc.
3Enter the old URL (or pattern) and new destination URL.
4Copy the generated code and paste it into your site's .htaccess file.
💡 Safety First: Always back up your existing .htaccess file before making changes. A syntax error in .htaccess causes a 500 Internal Server Error for all visitors.

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.

Try the Tool Now — 100% Free

No signup. No install. Works in your browser instantly.

🚀 Open Free Online Tool