.htaccess Redirect Generator

  • Free, no sign-up
  • Runs in your browser
  • Updated
Quick answer. The .htaccess Redirect Generator writes Apache mod_rewrite and mod_alias rules for 301 or 302 redirects, www and non-www, forcing HTTPS, trailing slashes and bulk redirects pasted from a CSV list.

.htaccess Redirect Generator tool

www handling

Trailing slash

Redirect type

1 redirect(s) recognised.

Back up your current .htaccess first. Rename the downloaded file to .htaccess. Apache and LiteSpeed only.

Runs in your browser. Your data never leaves your device.

How to use the .htaccess Redirect Generator

  1. 1Enter your domain and pick site-wide options: HTTPS, www or non-www, trailing slash.
  2. 2Add single redirects or paste a CSV of old path, new URL pairs.
  3. 3Choose 301 (permanent) or 302 (temporary).
  4. 4Copy the rules into the .htaccess file at your site root and test a few URLs.

What is a .htaccess redirect generator?

A .htaccess redirect generator writes the rules that make an Apache or LiteSpeed web server send visitors from one URL to another. This tool creates rules to force HTTPS, choose between www and non-www, add or remove trailing slashes, and redirect individual pages, including a bulk list pasted from a spreadsheet. You choose 301 (permanent) or 302 (temporary).

You paste the rules into the .htaccess file in your website's root folder, usually public_html on shared hosting.

How do .htaccess redirects work?

.htaccess is a configuration file that Apache reads on every request. The rules this tool writes use mod_rewrite, Apache's URL rewriting engine, described in the Apache documentation:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
  • RewriteCond sets a condition, here "the request is not HTTPS".
  • RewriteRule matches the path with a regular expression and sends the visitor to the new address.
  • R=301 makes it a permanent redirect; L means "stop processing more rules for this request".

Order matters. The tool outputs HTTPS first, then the host name, then trailing slashes, then individual pages, so most visitors are redirected only once or twice.

301 or 302: which should I use?

CodeMeaningUse it for
301Moved permanentlyNew domain, new URL structure, HTTPS, merged pages
302Found (temporary)A short promotion, maintenance, A/B tests
307 / 308Temporary / permanent, method keptAPIs and forms (not generated here)

Google treats permanent redirects as a strong signal to show the new URL in results, as explained in its redirects guide. Browsers also cache 301s, so test with 302 first if you are unsure, then switch.

Worked example

You moved a site from www.example.com to example.com on HTTPS and renamed an old page. Settings: domain example.com, Force HTTPS on, www → non-www, 301, and this CSV line:

/old-page.html,https://example.com/new-page/

Output:

RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

# Page redirects
RewriteRule ^old-page\.html$ https://example.com/new-page/ [L,R=301]

Dots in the old path are escaped (\.) because in regular expressions a plain dot matches any character. You can test patterns like this in the Regex Tester.

Tips

  1. Back up your current .htaccess before changing it. One typo can show a 500 error across the whole site.
  2. Keep WordPress rules intact. Put your redirects above the # BEGIN WordPress block.
  3. Watch out for proxies. If Cloudflare already forces HTTPS, an extra HTTPS rule with "Flexible" SSL can cause a redirect loop.
  4. Update internal links and your sitemap to the new URLs instead of relying on redirects. Rebuild it with the XML Sitemap Generator.
  5. Avoid chains. Redirect old URLs straight to the final page, not through several hops.
  6. Plan new URLs once. Clean, permanent slugs from the Slug Generator mean fewer redirects later.

How do I test redirects after uploading?

Open a private browser window and visit each old URL, including the http:// and www versions. You should land on the final address in one or two steps. For a closer look, your browser's developer tools (Network tab) show each redirect and its status code, so you can confirm you see 301 rather than 302. If the site shows a 500 error, restore your backup straight away and add the rules back one block at a time to find the problem line.

Limitations

These rules only work on Apache and LiteSpeed servers with mod_rewrite enabled. Nginx ignores .htaccess files completely, and static hosts such as Cloudflare Pages use a _redirects file instead. The generator does not handle query strings in old URLs: RewriteRule only matches the path, so redirecting ?id=5 needs an extra RewriteCond %{QUERY_STRING} line. If old URLs contain spaces or non-Latin characters, check their encoded form with the URL Encoder & Decoder. Always test a few old URLs in a private browser window after uploading.

Frequently asked questions

When should I use 301 vs 302?

Use 301 for permanent moves, such as a new URL structure. Use 302 for temporary changes. Search engines pass signals to the target of a 301.

Does .htaccess work on Nginx?

No. .htaccess is for Apache and LiteSpeed. Nginx uses return or rewrite directives in its server configuration.

Why do I get a redirect loop?

Usually because a rule matches its own target, or HTTPS is already forced by a proxy such as Cloudflare. Check conditions and test with one rule at a time.

Should I back up .htaccess first?

Yes. A single typo can return a 500 error for the whole site. Keep a copy so you can restore it quickly.

Last updated: . Written and tested by Abdul Moid Khan, ATechCraft. Read how we build and test tools.