Free .htaccess Redirect Generator

Generate Apache rewrite rules, 301/302 redirects, HTTPS forcing, and maintenance mode rules instantly for your website.

301 Redirects Force HTTPS URL Rewrites Maintenance Free Forever
301 Redirect
Permanent
302 Redirect
Temporary
Rewrite
Clean URLs
WWW
Host Check
HTTPS
SSL Force
Maintenance
503 Status
301 Permanent Redirect
Relative path. E.g. /old-page
302 Temporary Redirect
URL Rewrite
Regex allowed. Use parens () to capture.
Use $1 for first capture group.
Domain Rewrites
Force HTTPS

This rule forces all traffic to use HTTPS.

Maintenance Mode (503)
Allows you to bypass maintenance mode.
.htaccess
Ensure RewriteEngine On is present at the top of your file.

How to Use the .htaccess Redirect Generator

Creating Apache rewrite rules is quick and easy with our free online .htaccess generator. Follow these simple steps:

  1. Select redirect type - Choose from 301 Permanent, 302 Temporary, URL Rewrite, WWW/non-WWW, Force HTTPS, or Maintenance Mode.
  2. Enter the required URLs - Fill in the old URL/path and new destination. For rewrites, enter the friendly URL pattern and actual file path.
  3. Generate the rule - Click the generate button to create your .htaccess code with proper syntax and flags.
  4. Copy the code - Click "Copy" to copy the generated rule to your clipboard.
  5. Add to .htaccess - Paste the code into your .htaccess file. Remember to add RewriteEngine On at the top if not already present.
Important: Always backup your existing .htaccess file before making changes. A syntax error can make your website inaccessible.

Understanding HTTP Redirect Types

Choosing the right redirect type is crucial for SEO and user experience. Here's what each status code means:

301 Permanent Redirect

Use when: A page has permanently moved to a new URL.

  • Passes ~90-99% of SEO link equity
  • Browsers cache this redirect
  • Search engines update their index
  • Best for site migrations and URL changes
302 Temporary Redirect

Use when: A page is temporarily at a different URL.

  • Doesn't pass SEO value to new URL
  • Browsers don't cache this redirect
  • Search engines keep the original URL indexed
  • Good for A/B testing or temporary maintenance

Common .htaccess Use Cases

Here are the most common scenarios where you'll need .htaccess redirect rules:

Website Migration

Redirect old URLs to new ones when redesigning your site or changing URL structure.

Force HTTPS

Automatically redirect HTTP visitors to the secure HTTPS version of your site.

Clean URLs

Rewrite ugly URLs like /product.php?id=123 to friendly URLs like /product/123.

Best Practices for .htaccess Redirects

  • Always backup existing .htaccess before editing
  • Test in incognito to avoid browser cache issues
  • Use 301 for permanent moves to preserve SEO
  • Order matters - more specific rules should come first
  • End rules with [L] flag to stop processing
  • Avoid redirect chains (A→B→C) - redirect directly to final URL
  • Check for loops that cause infinite redirect errors
  • Use absolute URLs when redirecting to external domains

Frequently Asked Questions About .htaccess Redirects

.htaccess (hypertext access) is a configuration file used by Apache web servers. It allows you to control server behavior on a per-directory basis, including URL redirects, access control, URL rewriting, and custom error pages. The file is hidden (starts with a dot) and must be placed in your website's root directory or specific subdirectories.

Use 301 (Permanent) when a page has permanently moved and you want search engines to update their index and pass SEO value to the new URL. Use 302 (Temporary) when the redirect is temporary, like during maintenance or A/B testing, and you want search engines to keep the original URL indexed.

Infinite redirect loops occur when rule A redirects to URL B, but another rule redirects B back to A. Common causes: 1) Missing conditions like RewriteCond %{HTTPS} off before HTTPS forcing, 2) Conflicting rules, 3) Both www and non-www redirects active. Use browser developer tools (Network tab) to trace the redirect chain.

No, .htaccess is Apache-only. Nginx uses a different configuration format in nginx.conf or site-specific config files. If you're using nginx, you'll need to convert these rules to nginx syntax. However, many shared hosting providers use Apache, so .htaccess works on most web hosts.

RewriteEngine On enables the Apache mod_rewrite module for URL rewriting. This line must appear once at the top of your .htaccess file before any RewriteRule or RewriteCond directives. Without it, your rewrite rules won't work.