.htaccess Redirect Generator
Generate commented Apache .htaccess rules for 301 and 302 redirects, bulk redirect lists, query-string URLs, force HTTPS, www to non-www, trailing slashes, and domain moves.
Processed locally in your browser — nothing is uploaded.
.htaccess Redirect Generator
.htaccess
Output appears here…Test on a staging copy first — a typo in .htaccess returns a 500 error for the whole site — and remember that browsers cache 301s aggressively, so use 302 while you are still testing.
About .htaccess Redirect Generator
Pick the redirect you need and get Apache rules that use the simplest directive that does the job correctly. A plain path move becomes a one-line Redirect 301 /old /new from mod_alias. Anything mod_alias can't express — matching a query string, a regular expression, or a target that sits inside its own source — becomes a mod_rewrite RewriteRule, with RewriteEngine On written once at the top. Every block carries comments saying what it does.
The details that usually go wrong are handled for you. Paths are regex-escaped in RewriteRule patterns (so the dot in page.php doesn't match any character) and written without the leading slash, because that's how patterns are matched inside .htaccess. Query strings are matched with RewriteCond %{QUERY_STRING}, since a RewriteRule never sees them, and dropped from the redirect with the QSD flag. Literal $ and % in targets are escaped so Apache doesn't read them as back-references.
Bulk mode takes a pasted list — old and new separated by a space, a tab, or a comma, so a two-column CSV or spreadsheet copy works, header row and all, with an optional third column for 301 or 302. It flags lines that redirect to themselves, sources listed twice, and redirect chains (/a → /b → /c, which should point /a straight at /c) and loops. Because Redirect matches path prefixes and takes the first match, a deeper path like /shop/sale is moved above /shop so it isn't swallowed. If any line needs mod_rewrite, the whole list switches to it, since mod_rewrite runs before mod_alias whatever their order in the file.
Site-wide rules cover forcing HTTPS, www ↔ non-www, adding or removing trailing slashes, and moving a whole domain while keeping every path. HTTPS and www can be combined into one rule so visitors get a single redirect instead of a chain. Running nginx instead? The Nginx Redirect Generator produces the same redirects as nginx config.
Common uses
- Redirect a batch of old URLs after a site migration or WordPress permalink change
- Force HTTPS and pick www or non-www on shared hosting where .htaccess is all you can edit
- Retire old query-string URLs like /product.php?id=42 in favour of clean ones
Example
Input
Bulk list: /pricing-2023 /pricing /product.php?id=42 /products/blue-widget
Output
RewriteEngine On
RewriteRule ^pricing-2023$ /pricing [R=301,L]
RewriteCond %{QUERY_STRING} ^id=42$
RewriteRule ^product\.php$ /products/blue-widget [R=301,L,QSD]The query-string line needs mod_rewrite, so the whole list uses RewriteRule. Without it, both lines would be plain Redirect 301 directives.
Limitations
- .htaccess files only work where the host sets AllowOverride to permit them, and mod_rewrite must be enabled for the RewriteRule-based rules
- A query-string match is exact: id=42&ref=x or the same parameters in another order won't match
- Rules assume the .htaccess sits in the document root; in a subdirectory, the paths in patterns are relative to that directory
- Behind a CDN or load balancer that terminates TLS,
%{HTTPS}is always off — use the X-Forwarded-Proto condition noted in the generated HTTPS rule, or the redirect loops
Frequently asked questions
Should I use Redirect or RewriteRule in .htaccess?
Use Redirect 301 /old /new for a simple path move: it's one line and hard to get wrong. Use RewriteRule when you need to match a query string, a pattern, or a host name, or need an exact match, because Redirect matches path prefixes — /old also redirects /old/anything. This generator picks the right one for each redirect.
How do I redirect a URL with a query string in .htaccess?
Neither Redirect nor RewriteRule can see the query string on its own. Add RewriteCond %{QUERY_STRING} ^id=42$ on the line before the RewriteRule that matches the path, and add the QSD flag so the old query isn't appended to the new URL. Enter /product.php?id=42 as the old path here and the rules are written for you.
How do I force HTTPS and www with one redirect?
Combine both conditions with [OR]: RewriteCond %{HTTPS} off [OR] then RewriteCond %{HTTP_HOST} ^example\.com$ [NC], followed by RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]. Choose Force HTTPS, then "Also send to www", to generate it. Separate rules would send http://example.com through two redirects.
Why is my .htaccess redirect causing a redirect loop?
Usually because the target matches the rule again: Redirect 301 /blog /blog/new loops because /blog/new starts with /blog, and an HTTPS rule loops behind a proxy that makes %{HTTPS} always off. This tool switches to an exact-match RewriteRule in the first case and notes the X-Forwarded-Proto fix for the second; in bulk lists it flags chains and loops line by line.
Where do I put the .htaccess file?
In your site's document root (often public_html or www), the folder that holds your homepage. Put redirect rules near the top, before rules from your CMS such as WordPress's # BEGIN WordPress block, so they run first. Keep a backup: a syntax error makes Apache return 500 for the whole site.
Are the URLs and domains I enter sent anywhere?
No. The rules are generated entirely in your browser; unannounced domain moves and internal paths never leave your machine.