FormatterHQ

.htaccess Redirect Generator

Moving pages or switching to HTTPS? Paste old and new URLs and get Apache .htaccess redirect rules — Redirect or RewriteRule syntax — with optional HTTPS, www and slash rules.

Input TEXT
Output TEXT
Ready.

How to use the .htaccess Redirect Generator

  1. Paste one redirect per line: the old path (or full URL), a space, and the new URL.
  2. Choose the Redirect type (301, 302, 307, 308 or 410) and the Syntax (Redirect or RewriteRule).
  3. Optionally tick Force HTTPS and pick www and trailing-slash handling.
  4. Copy the rules into the .htaccess file in your site root and test on a staging server first.

An .htaccess redirect generator that avoids syntax errors

When URLs change — a redesign, a new CMS, merged articles — redirects keep visitors and search rankings on the right page. On Apache servers they usually live in the .htaccess file. A single typo there can take a site down with a 500 error, so this .htaccess redirect generator writes the rules for you from a simple list of old and new URLs.

Example

Input:

/old-page.html https://www.example.com/new-page
/products?id=42 /products/blue-widget

Output with the RewriteRule syntax:

# Generated .htaccess rules — test on a staging server first
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# 301 redirects
RewriteRule ^old-page\.html$ https://www.example.com/new-page [R=301,L]
RewriteCond %{QUERY_STRING} ^id=42$
RewriteRule ^products$ /products/blue-widget? [R=301,L]

Redirect or RewriteRule?

  • Redirect (mod_alias): short and readable — Redirect 301 /old /new. It matches path prefixes and cannot see query strings.
  • RewriteRule (mod_rewrite): exact regular-expression matches and query-string conditions. The generator escapes dots and special characters and appends ? to the target of a rule that matches a query string, so the old query string is dropped.

Avoid mixing both modules for the same URLs; mod_rewrite rules run first and can produce surprising results.

Choosing the status code

CodeMeaningUse for
301Moved permanentlyChanged URLs; passes ranking signals
302 / 307TemporaryMaintenance, A/B tests, seasonal pages
308Permanent, keeps methodAPIs and forms that POST
410GoneDeleted content with no replacement

Site-wide rules

Force HTTPS, Add/Remove www and Trailing slash generate host-level rules that run before your individual redirects. Pick one canonical form and use it consistently in links, canonical tags and your sitemap to avoid redirect chains.

Testing

Browsers cache 301 redirects aggressively, so test in a private window or with curl -I, and try the rules on a staging server first. Keep the redirects for at least a year. If your site runs on Nginx, the same logic uses return 301 in the server block instead of .htaccess. Once redirects are live, update your XML sitemap and check which paths crawlers may visit with the robots.txt generator.

Planning a migration

For a redesign or domain move, export every old URL (from your sitemap, analytics or a crawler), map each to its closest new equivalent in a spreadsheet, and paste the two columns here. Redirect to the most relevant page rather than the homepage — mass redirects to the homepage are treated like soft 404s by search engines. Avoid chains such as A → B → C by pointing old URLs straight to the final destination, and remove rules that point at pages which themselves redirect.

Line format

Each line needs the old path or URL and the new URL, separated by a space, a comma or an arrow (-> or =>). Full old URLs are reduced to their path and query string automatically. Lines starting with # are ignored, so you can keep comments in your mapping list. For the 410 status, the new URL can be omitted. Keep a copy of the original .htaccess before you paste new rules.

Privacy

The tool runs entirely in your browser. Nothing you type or paste is sent to our servers.

Frequently asked questions

Where is the .htaccess file?
In the document root of your website (often public_html). It is a hidden file because its name starts with a dot; enable "show hidden files" in your FTP client or file manager.
Why does my redirect not work with query strings?
The Redirect directive ignores query strings. Use the RewriteRule syntax, which adds a RewriteCond for the query string.
Should I use 301 or 302?
Use 301 (or 308) when the move is permanent; search engines then transfer signals to the new URL. Use 302 or 307 only for temporary changes.
My site shows a 500 error after editing .htaccess. What now?
Restore the previous file, then check that mod_rewrite is enabled and that each rule is on its own line. Test changes on a staging copy first.
Does this work on Nginx?
No. Nginx does not read .htaccess files; its redirects are configured in the server block with return or rewrite directives.

Last updated October 3, 2026

Guides

Related tools

Favicon Generator Make favicon.ico, Apple touch and Android icons plus site.webmanifest and HTML tags from an image or from text/emoji. ZIP download. Hreflang Tag Generator Generate hreflang annotations for multilingual sites as <link> tags, sitemap entries or HTTP headers, with code validation. HTML Link Generator Create an HTML anchor tag with link text, title, target _blank, nofollow or sponsored rel and simple inline styling. HTML Table Generator Generate HTML table code with any number of rows and columns, header row, caption, border and padding - with live preview. Hyperlink Generator Generate a hyperlink as HTML, Markdown, BBCode and plain text at once - ready for websites, READMEs, forums and e-mails. Lorem Ipsum Generator Generate lorem ipsum placeholder text by paragraphs, sentences or words, optionally wrapped in HTML <p> tags. Meta Tag Generator Generate SEO meta tags for your page head: title, description, keywords, robots, canonical, Open Graph and Twitter cards. Open Graph & Twitter Card Preview Paste your page’s meta tags and preview the link on Facebook, X/Twitter, LinkedIn, Slack and Discord, with fixes for missing tags. Robots.txt Generator Create a robots.txt file: allow or block paths, block AI crawlers and specific bots, set crawl-delay and add your sitemap URL. SERP Snippet Preview & Meta Length Checker Check title tag and meta description length in pixels and characters and preview your Google search result on desktop and mobile. UTM Campaign URL Builder Build Google Analytics campaign URLs with utm_source, utm_medium, utm_campaign, utm_term and utm_content, consistently formatted. XML Sitemap Generator Turn a list of URLs into a valid sitemaps.org XML sitemap with optional lastmod, changefreq and priority — ready for Search Console.