.htaccess Generator
Generate Apache .htaccess rules for redirects, rewrites, security headers, caching, compression, and more.
What is .htaccess?
.htaccess is a configuration file used by Apache web servers to control directory-level settings like redirects, URL rewriting, security, and caching without modifying the main server config.
Where should I place .htaccess?
Place the .htaccess file in the root directory of your website or in any subdirectory where you want the rules to apply. Rules affect the directory and all subdirectories.
Does .htaccess work with Nginx?
No, .htaccess is specific to Apache. Nginx uses a different configuration syntax. If you use Nginx, you need to convert .htaccess rules to Nginx configuration format.
Can .htaccess rules break my site?
Yes, incorrect .htaccess rules can cause 500 Internal Server Error or broken redirects. Always test rules and keep a backup of your working .htaccess file.
What is the difference between 301 and 302 redirects?
A 301 redirect is permanent and tells search engines to transfer ranking signals to the new URL. A 302 redirect is temporary and doesn't pass ranking signals. Use 301 for permanent moves and 302 for temporary changes.
How do I force HTTPS using .htaccess?
Use RewriteEngine On with RewriteCond %{HTTPS} off and a RewriteRule to redirect all HTTP traffic to HTTPS. This ensures secure connections for all visitors.
What is mod_rewrite?
mod_rewrite is an Apache module that provides powerful URL manipulation capabilities. It allows you to rewrite URLs, create redirects, and control access based on various conditions like hostname, request method, or HTTP headers.
How do I password protect a directory?
Use AuthType Basic, AuthUserFile, and Require valid-user directives in .htaccess. You'll also need to create a .htpasswd file with encrypted passwords using the htpasswd command.
How do I block specific IP addresses?
Use the Require directive with IP addresses: Require not ip 192.168.1.1 blocks a single IP. You can also block IP ranges or entire subnets.
How do I enable browser caching?
Use mod_expires with ExpiresByType directives to set cache expiration times for different file types. This improves site performance by reducing server load.
How do I enable GZIP compression?
Use mod_deflate with AddOutputFilterByType DEFLATE to compress text-based files like HTML, CSS, and JavaScript before sending them to browsers.
What are security headers?
Security headers like X-Frame-Options, X-Content-Type-Options, and Content-Security-Policy protect your site from clickjacking, MIME sniffing, and XSS attacks.
How do I prevent hotlinking?
Use mod_rewrite to check the HTTP_REFERER and block requests from external sites. This prevents other websites from using your images and bandwidth.
How do I create custom error pages?
Use the ErrorDocument directive followed by the error code and path to your custom page, like ErrorDocument 404 /404.html for custom 404 pages.
How to Use .htaccess Generator
Build Apache .htaccess rules for redirects, rewrites, security headers, caching, and compression without memorizing Apache syntax. Everything is generated locally in your browser.
- Pick the rule category you need — redirect, rewrite, security headers, caching, or compression.
- For a redirect, fill in the From path such as /old-page and the To path such as /new-page.
- Set Type to 301 (Permanent) for a moved-for-good URL or 302 (Temporary) while testing.
- Copy the generated snippet and paste it into the .htaccess file in your site's web root.
- Test the old URL afterward; clear CDN and browser caches if the change does not show up immediately.
Browsers cache 301 redirects aggressively — use 302 (Temporary) while testing so you do not get stuck with a stale permanent redirect.
Related Tools
- Chmod Calculator Free online chmod calculator to visualize and calculate Linux file permissions with checkboxes. Instantly convert between numeric (755, 644) and symbolic notation (rwxr-xr-x). Supports special permissions like setuid, setgid, sticky bit.
- ASCII Table Complete ASCII character encoding reference with decimal, hexadecimal, octal, binary codes, HTML entities, and character descriptions. Search and filter instantly.
- HAR Viewer Open HAR files online. Request table with status colors, sorting and filtering, headers, response body preview and a timing waterfall — parsed locally, nothing is uploaded.
- IBAN Validator Validate International Bank Account Numbers (IBAN) instantly. Check format, length, country code, and checksum for 80+ countries with real-time results.
- HTTP Request Tester Test REST APIs directly in your browser. Send GET, POST, PUT, DELETE requests with custom headers, body, and query parameters. View response status, headers, and JSON body instantly.
- Random Port Generator Generate random network port numbers from IANA standard ranges — well-known (1-1023), registered (1024-49151), and dynamic (49152-65535). Supports unique values, sorting, and bulk generation. 100% browser-based, no server needed.
- Robots.txt Generator Free online robots.txt generator. Create and customize robots.txt files to control search engine crawling, manage crawler access, and optimize your site's SEO with an easy visual editor.
- Sitemap Generator Free online XML sitemap generator. Add URLs, set priorities, change frequencies and create SEO-friendly sitemaps instantly in your browser.