.htaccess Generator

Last updated: November 27, 2026  •  Published by: NOFYI Editorial Team  •  Category: Developer Tools

Workspace

What is the .htaccess Generator?

The .htaccess Generator gives you a ready-to-use starter .htaccess file for an Apache server. An .htaccess file controls how Apache handles requests for a directory: redirects and custom error pages. This tool runs in your browser and builds the file from the options you pick: force HTTPS, force www or non-www, custom 301 redirects, and a custom 404 page.

How to Use the .htaccess Generator

  1. Open the .htaccess Generator page.
  2. Tick Force HTTPS if you want http requests redirected to https (it is ticked by default). Choose a domain style: do not force either, force non-www, or force www.
  3. Add custom 301 redirects, one per line as “old path, space, new URL” (for example “/old-page/ /new-page/”), and a custom 404 page path if you have one (for example “/404.html”).
  4. Click Generate .htaccess and copy the result from the page.
  5. Back up your existing .htaccess file, then paste the edited template into it and test your site.

Worked Example

Observed run: with Force HTTPS ticked, domain style “Do not force either”, no redirects and no 404 page, the tool generated a file starting with the comment “# Generated with the NOFYI .htaccess Generator — review before use.”, then “RewriteEngine On” and a Force HTTPS block (RewriteCond %{HTTPS} off, RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]). With Force www, one redirect “/old-page/ /new-page/” and a 404 page “/404.html” added, it also adds a Force www block, “Redirect 301 /old-page/ /new-page/”, and “ErrorDocument 404 /404.html”. The tool never adds compression, browser-caching, or security-header blocks.

Limitations

  • The tool only builds the rules it offers: force HTTPS, force www or non-www, custom 301 redirects, and a custom 404 page. It does not add compression, browser caching, or security headers — add those yourself if you need them.
  • The www rules assume HTTPS: if you untick Force HTTPS, review the generated URLs before saving (the tool warns you about this on the page).
  • Apache only. These rules do not work on Nginx or other servers that do not read .htaccess files.
  • The template is not validated against your server setup. A wrong redirect or error-page path can break pages or cause redirect loops, so test on staging first and keep a backup.
  • The Force www and Force non-www rules only appear if you choose them in the Domain style dropdown. If you choose “Do not force either”, no www rule is generated.

Frequently Asked Questions

Will this work on Nginx?

No. Nginx does not use .htaccess. Use these rules only on Apache servers with mod_rewrite enabled.

Do I need to edit the output before using it?

Only if you want to. The output is built from your options, so you can use it as generated — but check the error-page path exists and confirm the www choice before you upload it.

Does the tool read or check my existing .htaccess file?

No. It builds a new file from the options you pick and never reads your existing file, so paste it carefully and keep your backup.

Can I use the whole template as-is?

You can, but it is safer to test it on staging first. Check HTTPS redirects and error pages before publishing it live.