Skip to content

.htaccess Generator

Build an Apache .htaccess file: HTTPS and www redirects, moved pages, WordPress and Laravel rules, security, caching, compression, error pages and password protection.

Config GeneratorsRuns in your browserFree, no sign-up

Your site

What runs on it

Leave empty for the site’s root. For a site in a subfolder, enter it, such as /blog/.

Redirects

Each old address matches exactly, with or without a trailing slash. Add ?name=value to match a query string.

Security

Speed and error pages

.htaccess

The download is named htaccess.txt so your computer doesn’t hide it. Rename it to .htaccess when you upload it.

How to use the .htaccess generator

  1. Choose what runs on the site and tick the rules you want. The file updates as you go.
  2. Copy it, or download it and rename the file to .htaccess.
  3. Upload it to the folder it’s for, usually the site’s root (public_html on most shared hosting, public/ for Laravel). If a file is already there, keep a copy first and merge rather than replace: WordPress, caching plugins and your host may have added rules.
  4. Load a few pages, and check the redirects with the Redirect Checker and the headers with the Security Headers Checker.

The file is built in your browser; nothing you enter is sent to Cloudhim.

If you get a 500 error after uploading

Apache returns 500 Internal Server Error when a line in .htaccess uses a module that isn’t loaded or a directive the host doesn’t allow. Rename the file to take it out of use, then check the Apache error log, which names the line. The generator wraps optional rules in <IfModule> so a missing module is skipped rather than fatal. On your own server, turn on the modules with sudo a2enmod rewrite headers expires deflate and make sure the virtual host has AllowOverride All; without it Apache ignores the file completely.

Why HTTPS and www are one redirect

Many snippets redirect to HTTPS and then to the right host name in two steps, so http://www.example.com takes two hops. The generated rules do both in one 301, which is faster for visitors and cleaner for search engines.

Using Nginx instead?

Nginx doesn’t read .htaccess files. Paste the result into the .htaccess to Nginx Converter, or build a complete server block with the Nginx Config Generator.