Free .htaccess Generator

Generate Apache .htaccess rules without memorizing mod_rewrite syntax. Toggle HTTPS enforcement, www handling, trailing slashes, and hotlink protection, add custom 301 redirects, and copy a clean, commented config file ready to upload.

Generated .htaccess


    
Test before deploying. Upload to a staging site first and keep a backup of your existing .htaccess — bad rewrite rules can cause redirect loops.
Private by design. This tool runs 100% in your browser — your code is never uploaded to any server.

How to Use the Htaccess Generator

  1. Toggle the rules you need: HTTPS, www preference, trailing slash, directory listing.
  2. Add custom 301 redirects as old-path ⇒ new-URL lines.
  3. Set an optional custom 404 page and hotlink protection.
  4. Click Copy .htaccess or download the file, then upload it to your site root.

Features

The builder covers the most-used .htaccess tasks: force-HTTPS rewrites, www/non-www canonicalization, trailing-slash enforcement, custom 301 redirect lists, ErrorDocument 404 pages, Options -Indexes to hide directory listings, and image hotlink protection with your domain allowlisted. Output is commented section by section so you can audit every rule before deploying.

Benefits & Use Cases

Site owners migrating pages set up SEO-safe 301 redirects without touching regex; bloggers force HTTPS in one step; anyone hardening a shared host disables directory browsing and hotlinking in minutes. The generated syntax follows Apache best practices, avoiding the common RewriteRule mistakes that cause redirect loops.

Tips

Test rules on a staging site first — a bad rewrite can take a site offline; keep a backup of your existing .htaccess. Remember .htaccess only works on Apache (and LiteSpeed); Nginx users need server-block config instead.

Frequently Asked Questions

What is an .htaccess file?

A configuration file for Apache web servers. Placed in a directory, it controls redirects, access rules, error pages, and other server behavior for that directory without editing the main server config.

What is the difference between a 301 and 302 redirect?

A 301 is permanent: browsers and search engines transfer ranking signals to the new URL. A 302 is temporary. For moved pages, migrations, and www/HTTPS canonicalization, use 301.

Will these rules work on Nginx?

No. Nginx does not read .htaccess files — equivalent rules must go in the Nginx server block configuration. This generator targets Apache and compatible servers like LiteSpeed.

Why did my site break after uploading .htaccess?

The usual causes are a syntax error, a redirect loop (e.g. conflicting www rules), or mod_rewrite not being enabled. Restore your backup and add rules back one section at a time.

Where do I upload the .htaccess file?

Upload it to the directory it should apply to — usually the website’s document root (public_html or www). Rules also affect subdirectories unless overridden.

Related Tools