.htaccess 301 Redirect Generator

Build Apache .htaccess redirect rules for individual pages, www/non-www normalization, and forcing HTTPS — copy-paste ready.

Site-wide rules

Individual page redirects

Generated .htaccess

Runs entirely in your browser. Requires Apache's mod_rewrite to be enabled. Always back up your existing .htaccess before replacing it, and test on staging first — a bad rewrite rule can take your whole site down.

About this tool

This generates Apache mod_rewrite rules wrapped in an <IfModule mod_rewrite.c> block, which is what an .htaccess file needs to force HTTPS, normalize www vs. non-www, strip trailing slashes, or redirect specific old paths to new ones. Each site-wide rule is generated as its own RewriteCond/RewriteRule pair with an [L,R=301] flag — L stops further rule processing once matched, R=301 sends a permanent redirect — while individual page redirects use Apache's simpler Redirect directive instead.

Should I use a 301 or a 302 redirect?

301 means "moved permanently" and tells browsers and search engines to update their records and transfer the old URL's ranking signals to the new one — use it when a page has actually moved for good. 302 means "found" (temporary) and is meant for short-term redirects, like during maintenance, where you don't want search engines to treat the move as permanent.

Why doesn't this .htaccess file work on my host?

.htaccess rewrite rules only take effect on Apache servers with the mod_rewrite module enabled and AllowOverride permitting it for that directory. Nginx doesn't read .htaccess files at all — it needs the equivalent rules written directly into its own server block configuration instead.

What's the actual risk in a bad rewrite rule?

A malformed rule, or rules that conflict — like forcing both www and non-www at once — can create an infinite redirect loop or make the entire site return a server error, since Apache reads and applies .htaccess on every single request. That's why testing on staging and keeping a backup of the previous working file before replacing it matters more here than for most config changes.