🛠 Developer Tools Runs In-Browser Apache 2.4 Ready Production Ready

.htaccess Generator

Visually build a production-ready Apache .htaccess file — HTTPS/www redirects, security headers, browser caching, CORS, and one-click WordPress/Laravel/SPA rewrite presets. No Apache syntax to memorize, no server round-trip.

🔒 Nothing uploaded ⚡ Instant live preview 🧩 Framework presets 🆓 Free forever

Build Your .htaccess File

Start from a preset or configure each section manually — the preview below updates live.

🔀 Redirects & URL Structure
🧩 Framework / Rewrite Rules
🛡️ Security Rules

Security headers

⚡ Caching & Performance
🔎 SEO & Error Pages
🌐 CORS & API
🐘 PHP Configuration

⚠️ These directives only work with mod_php. Modern hosts using PHP-FPM will show a 500 error — use a .user.ini file instead in that case.

Rule blocks: 0
Warnings: 0
File size: 0 chars

            

How This .htaccess Generator Works

This tool assembles a real Apache configuration file from the options you choose, entirely in your browser — no server round-trip. Every generated block uses well-established, documented Apache directives, wrapped in <IfModule> checks where appropriate so a missing module fails gracefully instead of breaking your entire site.

What is .htaccess?

A .htaccess file ("hypertext access") is a plain-text configuration file that Apache reads on every request to the directory it lives in (and its subdirectories), letting you control redirects, URL rewriting, access restrictions, and headers without touching the main server configuration — ideal for shared hosting where you don't have access to httpd.conf.

Apache Web Server Overview

Apache HTTP Server is one of the most widely deployed web servers, powering a large share of the web — especially on shared and managed hosting, where .htaccess is often the only configuration surface available to site owners.

How .htaccess Works

Apache checks for a .htaccess file in every directory along the path of an incoming request (if AllowOverride is enabled for that directory) and merges its directives with the server's own configuration — meaning rules placed at your document root apply site-wide, while rules in a subdirectory only affect that subdirectory.

RewriteEngine, RewriteRule & RewriteCond Explained

RewriteEngine On turns on Apache's URL-rewriting engine (mod_rewrite) for that scope. A RewriteRule matches the requested URL against a regular expression and rewrites or redirects it to a target. A RewriteCond placed immediately before a RewriteRule adds an extra condition — like checking the HTTP_HOST or whether the connection is HTTPS — that must also be true for the rule to fire; multiple consecutive RewriteCond lines are combined with AND by default, or OR when explicitly flagged.

# Only redirect when the connection is plain HTTP...
RewriteCond %{HTTPS} off
# ...to the same URL, but on HTTPS
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

301 vs. 302 vs. 307 vs. 308 Redirects

301 (Moved Permanently) tells browsers and search engines the move is permanent and passes SEO value to the new URL — use it for canonical redirects. 302 (Found) signals a temporary move and is cached less aggressively. 307 and 308 behave like 302 and 301 respectively, but explicitly guarantee the request method (GET, POST, etc.) is preserved on the redirect, which matters for form submissions and APIs.

HTTPS & WWW Redirects

Search engines treat http:// and https://, and www. and non-www., as different URLs unless you redirect consistently to one canonical form — this generator handles both independently so you can pick exactly one HTTPS policy and one host policy.

URL Rewriting for Frameworks

Most PHP frameworks and single-page apps route every request through one entry file (index.php or index.html) and handle routing internally in JavaScript or PHP — the .htaccess rewrite rule's job is simply to send every request that isn't a real file or directory to that entry point.

Security Rules

Beyond headers, .htaccess can deny access to specific files by pattern (<FilesMatch>), restrict access by IP (<RequireAll> with Require ip / Require not ip), and disable risky defaults like directory listing (Options -Indexes) — all without needing root access to the server.

Browser Caching & Gzip Compression

mod_expires tells browsers how long to keep a cached copy of a file before re-checking with the server — long for rarely-changing assets like images and fonts, short for HTML. mod_deflate compresses text-based responses (HTML, CSS, JS, JSON) before sending them, cutting transfer size significantly at negligible CPU cost.

Hotlink Protection

Hotlinking is when another site embeds your images directly, consuming your bandwidth for someone else's page. The generated rule checks the Referer header and blocks image requests that didn't originate from your own domain.

CORS

Cross-Origin Resource Sharing headers tell browsers which other origins are allowed to fetch a resource via JavaScript — necessary when your API or static assets are consumed from a different domain than they're hosted on.

PHP Directives via .htaccess

php_value and php_flag only work when PHP runs as an Apache module (mod_php). Increasingly common PHP-FPM setups (most modern managed hosting and Docker-based deployments) will reject these directives with a 500 Internal Server Error — use a .user.ini file or your host's control panel instead in that case.

Custom Error Pages

ErrorDocument directives let you show a branded page instead of Apache's default error screen for statuses like 404 (Not Found) or 500 (Server Error).

Common Errors & Troubleshooting

  • 500 Internal Server Error right after upload — almost always a directive your host doesn't allow in .htaccess (ServerTokens, php_value on PHP-FPM) or a missing module; comment out sections one at a time to isolate it.
  • Redirect loops — usually caused by a proxy/load balancer that already terminates HTTPS, so %{HTTPS} never reports "on"; check %{HTTP:X-Forwarded-Proto} instead on such setups.
  • Rules seem ignored — confirm AllowOverride All (or at least the relevant override categories) is enabled for that directory in the main Apache config; some hosts restrict this.
  • Pretty URLs 404 — confirm mod_rewrite is enabled on the server (a2enmod rewrite on Debian/Ubuntu) and the file has been uploaded exactly as .htaccess, not htaccess.txt.

Apache & Security Best Practices

  • Always test a new .htaccess on a staging copy or with a quick rollback plan before deploying to production.
  • Prefer <IfModule> wrappers for anything module-dependent, so a missing module doesn't take the whole site down.
  • Keep sensitive-file protection and directory-listing rules on by default — they cost nothing and close common misconfiguration gaps.
  • Only enable HSTS once you've confirmed HTTPS works reliably site-wide — it's difficult to quickly undo once cached by browsers.
  • Combine HTTPS and www canonicalization goals, but understand two independent rules mean at most two redirect hops for the rare visitor hitting both wrong forms at once.

Privacy & Security

Every option you configure and every line of the generated file is built entirely inside your browser's JavaScript engine. Nothing is transmitted to ToolAdda's servers at any point.

Framework-Specific Rewrite Examples

These are the exact front-controller blocks generated by the Framework preset above, shown here for reference.

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine On
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

.htaccess vs. Apache VirtualHost Config

Aspect.htaccessVirtualHost / httpd.conf
Access neededFile upload only (shared hosting friendly)Root/server access
PerformanceRe-read on every requestLoaded once at server start — faster
ScopeDirectory and subdirectoriesWhole server or specific vhost
Best forShared hosting, per-site overridesVPS/dedicated servers with full control

301 vs. 302 Redirects

301 (Permanent)302 (Temporary)
SEO value transferYes, to the new URLMinimal/none — original URL stays authoritative
Browser cachingAggressively cachedNot cached by default
Use casePermanent moves, canonicalizationA/B tests, maintenance pages

Gzip vs. Brotli Compression

Gzip (mod_deflate)Brotli (mod_brotli)
Compression ratioGoodBetter, especially for text
Apache module availabilityUniversal, enabled almost everywhereLess commonly enabled on shared hosting
This generatorGenerates Gzip rules (broadly compatible)Not generated — enable via your host if mod_brotli is available

Frequently Asked Questions

What is .htaccess?

A .htaccess file is a per-directory Apache configuration file that lets you control redirects, URL rewriting, security rules, caching, and more without editing the main server configuration — just by placing a text file in a folder.

Is this generator free?

Yes. It's completely free, has no usage limits, and requires no account or sign-up.

Can I use it with WordPress?

Yes. The WordPress preset generates the exact front-controller rewrite block WordPress expects, plus HTTPS enforcement, sensitive-file protection, and caching — matching what WordPress itself writes to .htaccess.

Does it support Laravel?

Yes. The Laravel preset generates the standard public/.htaccess front-controller rules Laravel ships with, including Authorization header passthrough.

Can I generate redirects?

Yes. Add any number of custom redirects with 301, 302, 307, or 308 status codes, either as simple path-to-path redirects or regex/wildcard RewriteRule patterns.

How do RewriteRules work?

A RewriteRule matches an incoming URL against a regular expression and rewrites or redirects it to a target; RewriteCond directives placed before it add conditions (like checking the host or HTTPS status) that must also match for the rule to apply.

Is the generated file Apache compatible?

Yes. The output targets Apache 2.4+ syntax (the standard on virtually all current hosting), wraps module-dependent directives in <IfModule> checks so they fail gracefully if a module isn't loaded, and uses the modern Require syntax for IP restrictions instead of the deprecated Apache 2.2 Order/Deny syntax.

Can I protect my .env file?

Yes. Enable Protect Sensitive Files to deny public access to .env, .git, composer.json, package.json, and similar files that should never be publicly downloadable.

Can I enable Gzip?

Yes. Enable Gzip Compression to add a mod_deflate block that compresses text, CSS, JavaScript, JSON, XML, and SVG responses.

How do I force HTTPS?

Set HTTPS Redirect to "Force HTTPS" — this adds a RewriteCond/RewriteRule pair that 301-redirects any HTTP request to its HTTPS equivalent.

How do I redirect WWW to non-WWW (or the reverse)?

Set the WWW Redirect option to either "Redirect to www" or "Redirect to non-www" — only one canonical form should be chosen, and the generator prevents selecting both at once.

Can I disable directory listing?

Yes. Enable Disable Directory Listing to add Options -Indexes, which stops Apache from showing a raw file listing for folders without an index file.

Can I enable CORS?

Yes. Enable CORS in the API section and set your allowed origin, methods, and headers — useful for APIs or static assets consumed from a different domain.

Does it support Apache 2.4?

Yes, the generator specifically targets Apache 2.4+ syntax, including the Require-based access control introduced in 2.4 (replacing the older Order/Allow/Deny directives from 2.2).

Can I edit the generated rules?

Yes. The output is plain text — copy or download it and edit freely in your own editor before uploading to your server.

What Apache modules are required?

Redirects and rewrites need mod_rewrite; security/CORS headers need mod_headers; browser caching needs mod_expires; Gzip needs mod_deflate. Module-dependent blocks are wrapped in <IfModule> so the file won't error out if a module is missing — it will just silently skip that section.

How do I upload my .htaccess file?

Upload it via FTP/SFTP or your hosting file manager to your site's document root (or a subdirectory, to scope the rules to just that folder), making sure the filename is exactly .htaccess with no extension.

Can conflicting rules cause problems?

Yes — for example, an IP allow-list and an IP block list configured together, or HSTS enabled without HTTPS actually enforced. The generator surfaces these as warnings below the code preview so you can catch them before deploying.

Can I generate custom error pages?

Yes. Enter a path in the 404 or 500 error page fields to add ErrorDocument directives pointing to your custom error pages.

Is browser caching supported?

Yes. Enable Browser Caching to add sensible Expires headers per file type — long cache times for images and fonts, shorter for CSS/JS, and a short cache for HTML.

Can I block IP addresses?

Yes. List IPs to block, or alternatively list IPs to exclusively allow (useful for staging sites), using the modern Apache 2.4 Require syntax.

Does it support regex redirects?

Yes. Mark a custom redirect as "Regex" to generate a RewriteRule with a regular expression pattern and backreferences (like $1) instead of a simple Redirect directive.

Can I download the file?

Yes. Click Download to save the generated configuration directly as a .htaccess file, ready to upload.

Is everything generated locally?

Yes. All rule generation happens in your browser's JavaScript engine — nothing you configure is ever sent to ToolAdda's servers.

Can beginners use this tool?

Yes. Every option is a labeled toggle or field rather than raw Apache syntax, presets handle common frameworks automatically, and the educational content below the builder explains what each rule actually does.

Ready to Build Your .htaccess File?

Pick a preset or configure it your way — get a clean, production-ready Apache configuration in seconds, free and private.

⚡ Build My .htaccess Now
.htaccess Generator