21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Tool · WebJi® India

.htaccess Generator

Quick answer

An .htaccess generator writes Apache directives for common jobs so you paste syntax that already works. This free tool builds force-HTTPS and www redirects, 301 redirects, gzip compression, one-year image caching, dotfile blocking and a custom 404 page, then lets you copy or download the file. The rules run on Apache and LiteSpeed, not Nginx.

For site owners and developers on Apache or LiteSpeed hosting who need working redirect, HTTPS or caching rules without memorising the syntax.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
Freeno signup
needed
Price
Free
Signup
None
Built by
WebJi®
Support
24/7 email

Tick the options you need, add any 301 redirects, then copy or download the file. The rules run on Apache and on LiteSpeed, which reads .htaccess the same way; keep a copy of your working file before you replace anything.

Build your .htaccess

Runs in your browser
Old path only — the domain is implied. Full URLs also work.

Place the file in your site's public root (merge into an existing file rather than replacing rules you already run). Every plan that runs Apache honours these directives — see Linux hosting and shared hosting.

The output refreshes when you change a tick box or the www setting. After typing redirects or a 404 path, change any option once to refresh the code before you copy it.

What does the .htaccess generator write for each option?

Each option adds one block of Apache directives, in a fixed order: redirects first, then HTTPS and www rules, then compression, caching, dotfile blocking, directory listing and the 404 page. Optional modules are wrapped in IfModule tests so a server without them skips the block instead of failing.

Generator options and the directives they produce
OptionDirective writtenApache module
301 redirectsRedirectMatch 301 ^/old-path/?$ new-URL, one per linemod_alias
Force HTTPSRewriteCond %{HTTPS} off + RewriteRule … [R=301,L]mod_rewrite
www canonical formHost-header condition redirecting to www or non-wwwmod_rewrite
Gzip compressionAddOutputFilterByType DEFLATE for HTML, CSS, JS, JSON, SVGmod_deflate
Browser cachingExpiresByType: images 1 year, CSS and JS 1 monthmod_expires
Block dotfilesFilesMatch denying .git, .env and similar, except .well-knownmod_authz_core
Disable listingOptions -Indexescore
Custom 404ErrorDocument 404 /404.htmlcore

The .well-known exception matters: Let's Encrypt and other certificate checks read files from that folder, so blocking every dotfile would break SSL renewal.

When should a redirect be 301 and when 302?

Use 301 for a permanent move, because it tells search engines to transfer the old URL's signals to the new one; use 302 only while a change is temporary, such as a campaign page. Using 302 for a real migration keeps the old URL treated as the canonical one.

  • Single page: Redirect 301 /old-page /new-page
  • Pattern: RedirectMatch 301 ^/blog/(.*)$ /articles/$1
  • Temporary: the same lines with 302 while the test runs.

Point every redirect at the final URL, not at another redirect, since each hop adds a round trip and crawlers follow only a limited number. The .htaccess 301 redirect guide covers site moves in detail, and HTTP status codes explains what each code tells a browser.

How do RewriteRule flags and RewriteBase work?

A RewriteRule matches the path after the domain, without the leading slash in per-directory context, and the flags in square brackets decide the status code, whether processing stops and how matching behaves. Rules run top to bottom, so order matters as much as syntax.

RewriteEngine On
Required once at the top; without it every rewrite rule is ignored.
[L]
Stop processing further rules once this one matches.
[R=301]
Send an external redirect instead of an internal rewrite.
[NC]
Case-insensitive match, useful for legacy URLs typed in capitals.
[QSA]
Append the original query string to the target.
RewriteBase /
Set it when the site lives in a subdirectory, or rewritten paths resolve from the wrong folder.

A front-controller rule for pretty URLs needs a file check first, for example RewriteCond %{REQUEST_FILENAME} !-f then RewriteRule . /index.php [L]; without the condition, real images and CSS are routed through PHP too.

Why does a site show 500 errors after an .htaccess edit?

A 500 on every page right after an edit means the .htaccess file has a syntax error or uses a module the server lacks; restore the backup first, then find the line in the error log. Recovery takes seconds if you kept the previous file.

Common .htaccess mistakes and their symptoms
MistakeSymptomFix
No RewriteEngine OnRules look right and do nothingAdd it above the first rule
Unclosed quote500 errorQuote values that contain spaces in pairs
Deny from on Apache 2.4IP block silently ignored or 500Use Require not ip inside RequireAll
CRLF line endings or BOMSyntax error on line 1Save as UTF-8 without BOM, Unix line endings
Catch-all above a specific ruleSpecific rule never firesMove specific rules higher
Missing IfModule wrapper500 on servers without the moduleWrap optional blocks as the generator does

Where does the .htaccess file go and how do you test it?

Save the file as exactly .htaccess in the folder it should control, normally the site root (public_html), then test the old URLs in a private window. Most file managers hide dotted files until you switch on hidden items; finding .htaccess in cPanel shows where the option is.

  1. Download the current .htaccess as a backup before changing anything.
  2. Merge the generated blocks into the existing file rather than replacing rules a CMS such as WordPress already wrote.
  3. Upload as plain text and open the site in a private window.
  4. Request an old URL and confirm the status code is 301, not 302 or 404.
  5. If a page fails, read the error log, restore the backup and re-add one block at a time.

Nginx ignores .htaccess entirely, so on a VPS running Nginx the same rules must be rewritten as server-block directives; Apache vs Nginx explains the difference.

FAQ

Frequently asked questions

Will the generated file overwrite my WordPress rules?

Only if you replace the whole file. WordPress keeps its permalink rules between # BEGIN WordPress and # END WordPress; paste the generated blocks above that section and leave it untouched, or WordPress may rewrite it on the next settings save.

Why does the generator use RedirectMatch instead of RewriteRule for redirects?

RedirectMatch needs only mod_alias and no RewriteEngine, so it is simpler to read and works even where rewrite rules are disabled. The generator escapes special characters in the old path and accepts an optional trailing slash.

How do I block an IP address in .htaccess?

On Apache 2.4 put Require all granted and Require not ip 203.0.113.5 inside a <RequireAll> block. The older Deny from syntax depends on mod_access_compat and may be ignored on a modern server.

Is it safe to cache images for one year?

Yes, if you rename an image file when you change it. Browsers keep the old copy until the expiry, so replacing logo.png with a new logo under the same name may not show for returning visitors.

Does .htaccess slow a website down?

Slightly, because Apache checks for the file in every directory on each request. On shared hosting that cost is small and the file is the only way to set rules; on a VPS you can move rules into the main server configuration instead.

Generator output checked against its script on 15 November 2026 · Reviewed by the WebJi® team, Jaipur.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.