RubanTools

.htaccess Generator

Generate Apache .htaccess rules for HTTPS redirects, www/non-www, security headers, browser caching, directory protection and more.

Options
Redirects
Security
Performance
Custom 404 Error Page
.htaccess Output

                

.htaccess Generator - Apache Configuration Made Easy

An .htaccess (hypertext access) file is a directory-level configuration file used by the Apache HTTP Server - the web server powering an estimated 31% of all websites globally as of 2024. Placed in any directory, .htaccess rules are read by Apache on every request without requiring a server restart, making them the fastest way to configure redirects, access control, URL rewriting, and security headers without touching httpd.conf directly.

Why Indian Web Developers Use .htaccess

India had over 1.2 million registered web developers as of 2023, and a significant proportion host websites on shared cPanel-based hosting (providers like Hostinger India, BigRock, and MilesWeb) where root-level Apache configuration is unavailable. For these developers, .htaccess is the primary tool for enforcing HTTPS redirects, blocking bad bots, setting browser cache lifetimes, protecting directories with passwords, and implementing SEO-friendly clean URLs for PHP and WordPress sites. Indian e-commerce shops on shared hosting use .htaccess hotlink protection to prevent image bandwidth theft.

What This Generator Produces

Select the rules you need - HTTPS enforcement, www/non-www canonicalisation, custom error pages, cache control headers, CORS settings, security headers, and more - and this tool assembles a correctly formatted .htaccess file ready to upload via FTP or cPanel File Manager. Always test generated rules on a staging environment before applying to a live site.

.htaccess Questions

An .htaccess file is a directory-level configuration file for Apache web servers. It allows you to override server-wide settings for a specific directory without access to the main httpd.conf file. Common uses include: redirecting URLs (301/302); forcing HTTPS; blocking specific IPs or bots; setting custom 404/500 error pages; enabling Gzip compression; adding security headers (HSTS, X-Frame-Options); protecting directories with passwords (HTTP Basic Auth); and controlling browser caching for faster page loads.

Add these rules: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. This performs a 301 permanent redirect from all HTTP URLs to HTTPS. If your site is behind a load balancer or CDN (like Cloudflare), use RewriteCond %{HTTP:X-Forwarded-Proto} !https instead. This rule is generated automatically by this tool's HTTPS toggle.

.htaccess is specific to Apache web servers. NGINX does not read .htaccess files - its configuration is done in nginx.conf or sites-available. LiteSpeed Server (used by many Indian shared hosting providers like Hostinger and BigRock) is partially compatible - it reads .htaccess for rewrites and basic auth but has its own LSAPI-specific directives. OpenLiteSpeed uses its own native configuration. Check with your hosting provider which server you're running.

Create two files: (1) .htaccess with: AuthType Basic, AuthName "Protected Area", AuthUserFile /absolute/path/to/.htpasswd, Require valid-user; (2) .htpasswd with the encrypted password generated using the Apache htpasswd utility or an online htpasswd generator. The path in AuthUserFile must be an absolute server path - use phpinfo() to find the document root. This generator creates the .htaccess content; generate .htpasswd separately.

Key security headers: (1) X-Frame-Options: SAMEORIGIN - prevents clickjacking attacks; (2) X-Content-Type-Options: nosniff - stops MIME-type sniffing; (3) X-XSS-Protection: 1; mode=block - enables XSS filter in older browsers; (4) Referrer-Policy: strict-origin-when-cross-origin; (5) Strict-Transport-Security (HSTS) - enforces HTTPS for 1 year; (6) Content-Security-Policy - restricts resource loading. These are checked by Google Search Console, SSL Labs and security audit tools.