Hero Background

Next-Gen App & Browser Testing Cloud

Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Next-Gen App & Browser Testing Cloud

Free .htaccess Redirect Generator Online - TestMu AI (Formerly LambdaTest)

Generate SEO-friendly Apache mod_rewrite rules to force HTTPS, redirect www to non-www (or the reverse), and normalize trailing slashes, ready to paste into your .htaccess file.

Enter your domain

Enter the bare domain without a scheme or path. Any https:// or leading www. you paste is removed automatically.

Select redirect type

HTTP is always upgraded to HTTPS as part of the redirect.

Trailing Slash Settings

Trailing slash on directories
Trailing slash on non-filepath URLs
Trailing slash on query strings

Advanced Settings

Use permanent (301) or temporary (302) redirects
Use HSTS preload compatible two-step redirect
Redirect insecure proxy / load balancer requests to HTTPS

What is the .htaccess Redirect Generator?

On Apache servers, the .htaccess file controls how requests are rewritten and redirected. This tool writes the mod_rewrite rules for the most common canonicalization tasks, forcing HTTPS, picking a single www or non-www host, and enforcing a consistent trailing-slash style, so every visitor and search-engine crawler lands on one canonical URL. Everything is generated in your browser; nothing is uploaded.

How Each Option Affects the Output

  • Redirect type: redirects www to the root domain or the root domain to www. HTTP is always upgraded to HTTPS as part of the same redirect.
  • Trailing slash (directories / pretty URLs / query strings): independently add, remove, or ignore a trailing slash for each URL type.
  • 301 vs 302: switches every rule between a permanent and a temporary redirect.
  • HSTS two-step: splits the HTTPS upgrade into its own redirect (same host first) so the site stays HSTS-preload eligible.
  • Proxy / load balancer: also inspects X-Forwarded-Proto / X-Forwarded-SSL to avoid redirect loops behind a TLS-terminating proxy.

How to Use the Generated Rules

  • Enter your domain and choose your HTTPS, www and trailing-slash preferences.
  • Click Generate Redirect Code and copy the output.
  • Back up the existing .htaccess in your site root, then paste the rules near the top.
  • Make sure mod_rewrite is enabled, then test a few URLs in a private window.

Features of the .htaccess Redirect Generator

The generator focuses on getting canonical redirects right, including the edge cases that commonly cause redirect loops. These are the features that make the output production-ready.

  • HTTPS and www canonicalization: Force HTTPS and a single www or non-www host in one rule.
  • Trailing-slash control: Add, remove, or ignore slashes for directories, pretty URLs, and query strings.
  • 301 or 302: Switch every rule between a permanent and a temporary redirect.
  • HSTS-preload friendly: Optional two-step redirect that upgrades HTTPS on the same host first.
  • Proxy aware: Optional X-Forwarded-Proto / X-Forwarded-SSL checks to avoid loops behind a CDN or load balancer.
  • Browser-based: Rules are built locally and never uploaded.

Use Cases for the .htaccess Redirect Generator

Canonical redirects are a routine part of launches and migrations, and this tool sits alongside the other free server and config tools from TestMu AI.

  • SEO canonicalization: Consolidate HTTP/HTTPS and www/non-www variants onto one URL to avoid duplicate content.
  • Full server config: For error pages, caching, access control, and password protection, use the broader htaccess generator.
  • New project setup: Pair your server rules with a .gitignore generator when bootstrapping a repo.
  • Scheduled maintenance: Automate cache clears or backups with the crontab generator.

Frequently Asked Questions (FAQs)

What is an .htaccess redirect generator?

It builds Apache mod_rewrite rules for your .htaccess file that enforce a single canonical version of your site, forcing HTTPS, choosing www or non-www, and normalizing trailing slashes, so users and search engines always land on one URL.

Should I use 301 or 302 redirects?

Use 301 (permanent) for canonical HTTPS/www redirects, it passes SEO ranking signals and is cached by browsers. Use 302 (temporary) only for short-lived redirects you intend to remove later.

What is the HSTS preload compatible two-step redirect?

HSTS preload requires that the first redirect upgrades the request to HTTPS on the same host before any host change. When enabled, the generator emits a separate HTTPS upgrade first, then redirects www/non-www, keeping your site eligible for the HSTS preload list.

When do I need the proxy / load balancer option?

If your site sits behind a proxy, CDN or load balancer that terminates TLS, Apache may see the request as HTTP even though the visitor used HTTPS. This option also checks the X-Forwarded-Proto and X-Forwarded-SSL headers so you don't create a redirect loop.

What do the trailing-slash settings do?

They control whether a trailing slash is added (Include), stripped (Remove), or left alone (Ignore), separately for real directories, for pretty/non-file URLs, and for URLs that carry a query string. Pick one consistent style to avoid duplicate-content URLs.

Where do I put the generated rules?

Paste them near the top of the .htaccess file in your site's document root, on an Apache server with mod_rewrite enabled. Always back up your existing .htaccess first and test after deploying.

Does this work on Nginx or only Apache?

These rules are for Apache, which reads .htaccess. Nginx does not use .htaccess; it needs equivalent directives in its server config. Use this generator when your site runs on Apache or LiteSpeed.

Did you find this page helpful?

More Tools

Related Tools
Code Formatters & Minifiers
Code Converters

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests