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
| Code | Meaning | Use for |
|---|---|---|
| 301 | Moved permanently | Changed URLs; passes ranking signals |
| 302 / 307 | Temporary | Maintenance, A/B tests, seasonal pages |
| 308 | Permanent, keeps method | APIs and forms that POST |
| 410 | Gone | Deleted 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.