Skip to main content
wp-config.org

Search tools

WordPress configuration

.htaccess generator for WordPress and WooCommerce

Use this WordPress .htaccess generator to protect wp-config.php, hidden files and the uploads folder, then add only the extras your site needs: HTTPS, security headers, WooCommerce protection and caching. Every option explains what it does and what it can break, and the matching Nginx rules appear beside the .htaccess.

  • Apache 2.4 and LiteSpeed
  • WooCommerce ready
  • Nginx rules included

Free, no sign-up. It runs in your browser, so nothing you type is sent to this site.

Nothing you enter leaves your browser.

This tool runs in your browser and needs JavaScript. Turn JavaScript on and reload the page.

.htaccess

Using the files

Where does each file go?
  • .htaccess goes in the folder WordPress is installed in, next to wp-config.php and index.php. If the file already exists, paste the # BEGIN wp-config.org blocks above # BEGIN WordPress and leave blocks that plugins manage, such as # BEGIN LSCACHE, where they are.
  • wp-content/uploads/.htaccess stops scripts from running in the uploads folder. Upload it to that folder.
  • woocommerce_uploads/.htaccess and wc-logs/.htaccess replace the files WooCommerce writes in those folders, using Apache 2.4 syntax.
  • The Nginx rules go in your site's Nginx configuration instead. Nginx ignores every .htaccess file.
What if the site shows a 500 error?

Put your backup back first. A 500 error after editing .htaccess usually means the host does not allow a directive in .htaccess. Options, compression (AddOutputFilterByType) and browser caching (ExpiresByType) are the usual causes, because no IfModule check can catch a directive the host forbids. Add the blocks back one at a time to find it, then leave that one out.

Every rule from an optional Apache module is wrapped in an IfModule check, so a missing module switches its rule off instead of breaking the site. Check each protection afterwards, for example with curl -I https://your-domain/wp-config.php, which should answer 403.

Apache, LiteSpeed and OpenLiteSpeed

Apache 2.4 and LiteSpeed Enterprise read the same file. The rules use Apache 2.4 syntax only (Require, never Order, Allow or Deny). With the LiteSpeed Cache plugin, keep its blocks at the top of the file.

OpenLiteSpeed reads only rewrite rules from .htaccess and ignores everything else, so in that mode every protection is written as a rewrite rule, no folder files are made, and the header comment lists the settings to make in the WebAdmin console. Restart OpenLiteSpeed after each change.

Behind Cloudflare or another proxy

Behind a proxy, your server sees every request arrive over plain HTTP, so a normal HTTPS redirect sends visitors round in circles. With the proxy switch on, the redirect and HSTS also trust the X-Forwarded-Proto header the proxy adds. In Cloudflare, use SSL/TLS mode Full (strict): Flexible mode connects to your server over HTTP.

WordPress needs to know about the proxy too, or wp-admin can loop. The wp-config.php generator writes the lines for it.

What you can do

  • wp-config.php, hidden file and uploads protection on by default

  • Optional HTTPS, HSTS, header and xmlrpc.php rules, risks explained

  • WooCommerce download, log and cart-cache protection

  • Cloudflare proxy and OpenLiteSpeed modes

  • Matching Nginx rules and a ZIP with every file and a README

How to create a WordPress .htaccess file

  1. Describe your server

    Choose Apache, LiteSpeed or OpenLiteSpeed, say whether the site is behind Cloudflare or another proxy, and enter the domain if you want redirects or hotlink blocking.

  2. Choose the rules

    Keep the four default protections, then add only the options you need. Read the warning under each one, and tick WooCommerce if the site runs a shop.

  3. Back up, paste and test

    Back up your .htaccess, paste the new blocks above # BEGIN WordPress, upload the folder files, then load the home page, wp-admin and checkout. If anything shows a 500 error, put the backup back.

A safer .htaccess without guesswork

Most .htaccess snippets online are copied from old guides. They often use Apache 2.2 syntax, send HSTS only where Apache handles HTTPS itself, or block things WordPress and WooCommerce need. This .htaccess generator writes Apache 2.4 rules only, wraps every rule from an optional module in an IfModule check, and puts each group between named markers above the WordPress block, where WordPress never overwrites them.

Safe defaults, risky options marked

Only four protections start on: wp-config.php, hidden files such as .env and .git, directory listing and PHP in the uploads folder. They do not change how a normal site works. Everything else is off until you choose it, and each option says what it can break, such as Jetpack when xmlrpc.php is blocked or the Customizer preview with X-Frame-Options.

WooCommerce, Cloudflare and OpenLiteSpeed

For a shop it protects downloadable product files and logs in Apache 2.4 syntax, keeps cart and payment requests out of caches and never blocks payment callbacks, the REST API or admin-ajax.php. Behind Cloudflare it detects HTTPS from the proxy's header, which avoids redirect loops. For OpenLiteSpeed, which only reads rewrite rules, every protection is written as a rewrite rule.

Know the limits

.htaccess cannot set server-wide options such as ServerTokens, restore visitor IP addresses behind a proxy or rate-limit logins. Check your headers after uploading with the HTTP header checker and the HSTS checker. On Nginx, use the matching rules shown beside the .htaccess, or start a full configuration with the Nginx config generator.

Frequently asked questions

Where is the .htaccess file in WordPress?

In the folder WordPress is installed in, next to wp-config.php and index.php. Its name starts with a dot, so file managers and FTP programs hide it unless you show hidden files. WordPress creates it when you save Settings, Permalinks, if the server lets it write the file.

Will these rules replace the WordPress permalink rules?

No. Paste the generated blocks above # BEGIN WordPress and keep your own WordPress block. WordPress only rewrites the lines between its own markers. Add the permalink block from this .htaccess generator only if your .htaccess is missing.

Why does my site show a 500 error after editing .htaccess?

Usually the host does not allow one of the directives in .htaccess. Options, compression and browser caching lines are the common causes. Put your backup back, then add the blocks one at a time to find the one your host refuses.

Should I block xmlrpc.php?

Only if nothing on the site uses it. Blocking it stops XML-RPC password guessing and pingback spam, but it breaks Jetpack and services that rely on its connection, pingbacks and apps that publish over XML-RPC.

Does .htaccess work on Nginx?

No. Nginx ignores .htaccess files. The generator shows the same rules written for Nginx beside the .htaccess, to merge into your site's server block before you run nginx -t and reload.

Does it work behind Cloudflare?

Yes. Turn on the proxy switch so the HTTPS redirect and HSTS read the X-Forwarded-Proto header Cloudflare sends, and use SSL/TLS mode Full (strict). WordPress also needs a few lines in wp-config.php so it knows visitors use HTTPS.

Related tools

  • .htaccess to Nginx

    New (added recently)

    Convert a WordPress or WooCommerce .htaccess file into Nginx rules, with every line explained.

  • Generate a wp-config.php with database settings, new salt keys and explained options.

  • Generate an Nginx config for WordPress with TLS, caching, HTTP/2 and HTTP/3.

  • Check a URL’s HTTP response headers and redirect chain.