.htaccess Generator
Generate Apache .htaccess rules visually. Create redirects, URL rewrites, security headers, caching rules, gzip compression, custom error pages, and CORS settings. Template presets for WordPress, Laravel, SPA, and more.
Rule Builder
Generated .htaccess
0 lines
What is an .htaccess File?
The .htaccess (hypertext access) file is a powerful configuration file used by Apache web servers. It lets you control URL redirects, access rules, security settings, caching behavior, and much more — all without touching the main server configuration.
Changes take effect immediately without restarting the server. The file sits in your website's root directory and applies rules to that directory and all subdirectories beneath it.
Template Presets
WordPress — Pretty permalinks with index.php routing, wp-admin protection, security headers, gzip compression, and browser caching.
Laravel — Routes all requests through public/index.php, enables URL rewriting, security headers, and compression.
Static Site — Optimized for HTML/CSS/JS sites with aggressive caching, gzip compression, security headers, and custom error pages.
SPA (React/Vue/Angular) — Catches all routes and rewrites to index.html for client-side routing. Includes caching and compression.
Drupal — Clean URLs with index.php front controller, file access rules, and performance optimization.
How to Use — 3 Simple Steps
Configure Your Rules
Use the rule builder on the left to toggle features on and off. Expand each category to see available options. Or select a template preset to start with recommended settings for your platform.
Review the Output
The generated .htaccess code updates in real-time as you toggle rules. Review the syntax-highlighted output and check for any warnings about conflicting rules.
Copy or Download
Copy the generated code to clipboard or download it as an .htaccess file. Upload the file to your website's root directory.
Common Rules Reference
| Rule | Directive | Purpose |
|---|---|---|
| Force HTTPS | RewriteCond / RewriteRule | Redirect HTTP → HTTPS for security |
| 301 Redirect | Redirect 301 | Permanent URL redirect (SEO-friendly) |
| Gzip | mod_deflate | Compress responses by 60-80% |
| Cache | mod_expires | Tell browsers to cache static files |
| Security Headers | Header set | Prevent XSS, clickjacking, MIME sniffing |
| Block Directory | Options -Indexes | Hide folder file listings |
Pro Tips
Test Before Deploying
Always test your .htaccess file on a staging server first. A syntax error can take down your entire website with a 500 Internal Server Error.
Order Matters
Apache processes .htaccess rules top to bottom. Place redirects before rewrite rules, and more specific rules before general ones.
Backup First
Always backup your existing .htaccess file before making changes. Keep a copy of the working version so you can quickly restore it.
Check mod_rewrite
Most URL rewriting requires mod_rewrite to be enabled. Check with your hosting provider if redirect rules don't work.
Frequently Asked Questions
What is an .htaccess file?
An .htaccess (hypertext access) file is a configuration file for Apache web servers. It allows you to control URL redirects, security settings, caching rules, and more on a per-directory basis without modifying the main server configuration.
Where do I place the .htaccess file?
Place the .htaccess file in the root directory of your website (public_html or www folder). The rules will apply to that directory and all subdirectories. You can also place separate .htaccess files in subdirectories for directory-specific rules.
Will these rules work on Nginx?
No. .htaccess files only work on Apache web servers. Nginx uses a different configuration syntax (nginx.conf). If you use Nginx, you will need to convert these rules to Nginx format. However, many shared hosting providers use Apache.
How do I force HTTPS on my website?
Enable the "Force HTTPS" toggle in the Redirects section. This generates RewriteCond and RewriteRule directives that detect non-HTTPS connections and redirect them to the HTTPS version. Make sure you have a valid SSL certificate installed first.
Can I use multiple rules together?
Yes! You can enable any combination of rules. The generator organizes them into proper sections with comments. The conflict detection feature will warn you if any rules might interfere with each other, like having both "add trailing slash" and "remove trailing slash" enabled.