DocumentsImagesMediaPDF Tools

.htaccess Generator

Generate Apache server rules in seconds.

# Generated by Convertir.ai

# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Remove WWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]

# Custom Error Pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

# Enable Gzip Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css
  AddOutputFilterByType DEFLATE application/javascript application/json
  AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# Browser Caching
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
</IfModule>
Processed in your browser

Configure Apache without touching the server

Apache compatible

Generates valid .htaccess directives for Apache 2.2 and 2.4, the most common shared hosting versions.

Safe output

The generator produces tested code. Review the result before uploading to your server.

Instant

The .htaccess file is generated in your browser instantly. No signup, no waiting.

Private

Nothing is sent to any server. Your configuration stays on your device.

Three steps, no hassle

1

Select your rules

Enable the options you need: HTTPS redirect, www, Gzip, cache. No code required.

2

Copy the generated .htaccess

The file is generated instantly in your browser. Copy it with one click.

3

Upload to your server

Place the .htaccess file in your website root and changes apply immediately.

Got questions?

.htaccess (Hypertext Access) is an Apache configuration file that controls server behavior at the directory level, without modifying the global server configuration. It allows you to set up redirects, control access, compress files, define custom error pages, and rewrite URLs. Each directory can have its own .htaccess and its directives apply only to that directory and its subdirectories.

HTTPS redirection is implemented with mod_rewrite in .htaccess: RewriteEngine On, RewriteCond %{HTTPS} off, RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. The 301 code signals a permanent redirect, which browsers and search engines cache. Make sure your SSL certificate is active before enabling this rule to avoid redirect loops.

The choice between www and non-www is mainly preference and branding, but you should pick one as canonical and redirect the other. To redirect non-www to www: RewriteCond %{HTTP_HOST} !^www\. and RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. Google treats both versions as distinct URLs, so the redirect prevents duplicate content issues.

Gzip compression reduces the size of text files (HTML, CSS, JS, JSON, XML) by 60-90% before sending them to the browser. This means faster page loads, reduced bandwidth usage, and better PageSpeed scores. It's enabled with mod_deflate in .htaccess: AddOutputFilterByType DEFLATE text/html text/css application/javascript. Binary files like images and PDFs are already compressed and don't benefit from Gzip.

Cache-Control and Expires headers tell the browser how long it can store a resource before requesting it again from the server. With .htaccess you can define different cache times per file type: images and fonts can be cached for 1 year (max-age=31536000), CSS and JS for several months, HTML for a few days or none. This drastically reduces the number of requests on repeat visits, speeding up load times up to 80% for returning users.

.htaccess history: from NCSA HTTPd 1993 to modern Apache

The .htaccess file has its roots in the NCSA HTTPd server, developed at the National Center for Supercomputing Applications in the early 1990s. The first version of the per-directory access file appeared in NCSA HTTPd 1.3 around 1993. When Apache HTTP Server emerged in 1995 as a fork of NCSA HTTPd with community patches, it inherited the .htaccess system. The name comes from 'hypertext access', reflecting its original use for controlling directory access with passwords.

Apache evolved through two multi-processing models (MPM): prefork (one process per connection, compatible with non-thread-safe modules like mod_php) and worker/event (multi-threaded, higher performance). The mod_rewrite module, introduced in Apache 1.2 in 1996, transformed .htaccess into an extremely powerful URL rewriting tool. With mod_rewrite you can create friendly URLs, implement complex redirects, block bots, and configure advanced security rules.

Nginx, the web server that surpassed Apache in market share for high-traffic sites, has no direct equivalent of .htaccess. In Nginx, the equivalent configuration is done in the server{} block of nginx.conf, which requires root access to the server. This keeps Apache's .htaccess relevant for shared hosting where users don't have root server access. URL rewriting in Nginx uses location and rewrite directives inside the server block.