liminfo

.htaccess Generator

Free web tool: .htaccess Generator

Options

Redirects

.htaccess Output

# 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 [R=301,L]

# Enable Gzip Compression
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/plain text/css
  AddOutputFilterByType DEFLATE text/javascript application/javascript
  AddOutputFilterByType DEFLATE application/json application/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/svg+xml "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType text/html "access plus 1 hour"
</IfModule>

About .htaccess Generator

The .htaccess Generator builds a ready-to-deploy Apache configuration file based on the options you choose. It covers the most common Apache directives in a single tool: forcing HTTPS via RewriteRule, removing or adding the www subdomain prefix, enabling Gzip compression with mod_deflate, setting long-term browser caching with mod_expires for images, CSS, JavaScript, and HTML, adding HTTP Basic Authentication with .htpasswd, configuring custom 404 and 500 error pages, and adding permanent (301) or temporary (302) URL redirects.

Apache web server administrators, WordPress developers, and web hosting users reach for .htaccess files when they need to control server behavior without modifying the main httpd.conf. This generator removes the need to memorize syntax by providing checkboxes and input fields for each feature — the correct Apache directives are assembled automatically as options are toggled, and the output updates in real time.

The entire generation process runs in your browser using JavaScript. No data is sent to any server. Once you have configured the desired options, click Copy to copy the file contents to your clipboard, then paste it into the .htaccess file at the root of your Apache web directory. Always test changes in a staging environment before applying them to production.

Key Features

  • Force HTTPS: generates RewriteEngine + RewriteCond %{HTTPS} off + 301 redirect to https://
  • WWW handling: add www prefix, remove www prefix, or leave unchanged — uses RewriteCond and R=301,L flags
  • Gzip compression: adds mod_deflate IfModule block for HTML, CSS, JavaScript, JSON, and XML content types
  • Browser caching: configures mod_expires with per-type expiry rules — 1 year for images/SVG, 1 month for CSS/JS, 1 hour for HTML
  • Custom error pages: sets ErrorDocument directives for 404 and 500 with configurable target paths
  • Password protection: adds AuthType Basic, AuthName, AuthUserFile, and Require valid-user directives
  • Multiple URL redirects: add 301 or 302 redirect rules with customizable source and destination paths
  • Real-time output preview with one-click copy — paste directly into your server's .htaccess file

Frequently Asked Questions

What is an .htaccess file?

An .htaccess (hypertext access) file is a directory-level configuration file for Apache web servers. It allows you to override server settings for a specific directory without editing the main Apache configuration. Common uses include URL redirects, HTTPS enforcement, access control, and custom error pages.

How do I force HTTPS with .htaccess?

Enable the "Force HTTPS" option in the generator. It will produce RewriteEngine On, a RewriteCond checking if HTTPS is off, and a RewriteRule that redirects all traffic to the https:// version of the URL with a 301 permanent redirect. Paste this at the top of your .htaccess file.

What is the difference between 301 and 302 redirects?

A 301 redirect is permanent — search engines transfer link equity to the new URL and update their index. A 302 redirect is temporary — search engines keep the original URL in their index. Use 301 for permanently moved content and 302 for temporary URL changes.

How does Gzip compression work in .htaccess?

The generator adds an IfModule mod_deflate.c block with AddOutputFilterByType directives that tell Apache to compress HTML, plain text, CSS, JavaScript, JSON, and XML responses before sending them to the browser. This typically reduces response size by 60–80%, speeding up page load times.

What does browser caching do and what values are set?

Browser caching tells browsers how long to store static resources locally before re-fetching. The generator uses mod_expires to set 1 year for JPEG, PNG, and SVG images, 1 month for CSS and JavaScript files, and 1 hour for HTML documents.

How do I add password protection with .htaccess?

Enable the Password Protection option and enter the .htpasswd file path. The generator adds AuthType Basic, an AuthName label, AuthUserFile pointing to your .htpasswd file, and Require valid-user. You must create the .htpasswd file separately using the htpasswd command-line tool or an online generator.

Where should I place the .htaccess file?

Place the .htaccess file in the root directory of your website (usually public_html/ or www/) for site-wide rules. For directory-specific rules, place it in that subdirectory. Apache processes each .htaccess file it finds while traversing the path to the requested file.

Will this .htaccess work on Nginx or other servers?

.htaccess is Apache-specific. Nginx does not support .htaccess files; its configuration lives in server block files. If you are using Nginx, LiteSpeed with .htaccess support enabled, or a shared hosting environment that explicitly supports Apache .htaccess, this generator will be applicable.