.htaccess Generator for Apache & WordPress
Tick what you need and get a tested, commented .htaccess file for Apache. HTTPS and www redirects, 301s, caching, compression, security headers and WordPress rules are all covered.
- Free
- No sign-up
- Runs in your browser
Start from a preset
Everything runs in your browser. What you type here is never uploaded, stored or sent anywhere.
What is a .htaccess file?
.htaccess is a small configuration file that the Apache web server reads from your site's folders. It lets you change how the server behaves without touching the main server config, which is why it is the go-to tool on shared hosting. With a few lines you can redirect old URLs, force every visitor onto HTTPS, speed up the site with caching and compression, and block things you do not want.
The catch is that one wrong character can take the whole site down with a 500 error, and the rules are picky about order. This generator writes each block the way Apache expects it, wraps rules in IfModule checks so a missing module does not break the site, and puts the WordPress rewrite block last where it belongs.
Note that .htaccess is for Apache (and LiteSpeed, which reads it too). If your server runs Nginx, use the Nginx Config Generator instead. For scheduled tasks on the same server, the Cron Expression Generator will help.
How to generate and install a .htaccess file
- Start with a preset (WordPress, Static site or Hardened) or tick the options one by one.
- Fill in any details the options ask for, such as your domain for hotlink protection or the list of redirects.
- Read the notes under the output. They point out anything that needs care, like HSTS or long cache times.
- Download the file or copy it. Back up your existing
.htaccessfirst, from your hosting file manager or over FTP. - Upload it to your site's root folder (usually
public_html) and load your site in a private window to test. If you see a 500 error, restore the backup and remove the last option you added.
What people use it for
- Moving a site to HTTPS and making sure there is only one version of every URL.
- Redirecting old URLs to new ones after a redesign or a change of permalink structure, so you keep your SEO value.
- Speeding up a WordPress site with compression and browser caching.
- Hiding sensitive files such as
wp-config.phpand.env, and switching off directory listings. - Stopping other websites from hotlinking your images and eating your bandwidth.
Frequently asked questions
Where do I put the .htaccess file?
In the root folder of your website, which on most hosts is public_html or www. It is a hidden file because its name starts with a dot, so turn on "show hidden files" in your file manager. Rules apply to that folder and everything below it.
Will this work on Nginx?
No. Nginx does not read .htaccess files. LiteSpeed does, so it works there. For Nginx, use the Nginx Config Generator to write the equivalent rules in your server block.
I got a 500 Internal Server Error. What now?
Restore your backup, then add options back one at a time to find the one that fails. The most common causes are php_value lines on a server that runs PHP-FPM, or a module such as mod_headers that is not enabled and a rule that is not wrapped in an IfModule check. The generated rules use IfModule wrappers where possible to avoid this.
What is the difference between a 301 and a 302 redirect?
A 301 is permanent and tells search engines to pass the old page's ranking to the new address. A 302 is temporary. Use 301 for moved or renamed pages and 302 only when the move really is short-term.
Is it safe to enable HSTS?
HSTS makes browsers refuse plain HTTP for your domain for a year. That is great once everything works on HTTPS, but it is hard to undo if something is not ready. Test with HTTPS forced for a while first, and add includeSubDomains only if all subdomains support HTTPS.
Does this replace my existing WordPress .htaccess?
The generated file includes the standard WordPress block when you tick that option. If you use a caching or security plugin, it may add its own lines to .htaccess between its own markers. Keep a copy of those sections before you replace the file, then paste them back.
