Pixvert

.htaccess Generator — Free

Build an Apache .htaccess file with HTTPS redirects, caching, security headers, custom errors, and more. No signup required.

Domain & HTTPS

Performance

Security

PHP

Custom error pages

Custom redirects

No custom redirects. Click + Add to add one.

.htaccess
# Generated by Pixvert .htaccess Generator
# https://pixvert-one.vercel.app/tools/htaccess-generator

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

# Directory listing
# -----------------
Options -Indexes

# Custom error pages
# ------------------
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

# Enable Gzip compression
# -----------------------
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
  AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript application/x-javascript
  AddOutputFilterByType DEFLATE application/json application/ld+json
</IfModule>

# Browser caching (Expires)
# -------------------------
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "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 day"
</IfModule>

# Security headers
# ----------------
<IfModule mod_headers.c>
  Header set X-XSS-Protection "1; mode=block"
  Header always append X-Frame-Options SAMEORIGIN
</IfModule>

# PHP settings
# ------------
<IfModule mod_php.c>
  php_value upload_max_filesize 64M
  php_value post_max_size 64M
</IfModule>

Performance rules

Gzip compression and browser caching headers speed up page loads automatically.

🔒

Security headers

XSS protection, clickjacking prevention, hotlink blocking and CORS settings in one click.

↪️

Redirects & rewrites

301/302 custom redirects, HTTPS enforcement, and www/non-www canonicalization.

What is a .htaccess generator?

A .htaccess file is a configuration file used by the Apache web server to control behavior on a per-directory basis — redirects, caching rules, security headers, and more — without needing to edit the main server configuration. Pixvert's .htaccess generator builds this file for you visually, based on the options you select.

Writing .htaccess rules by hand requires knowing Apache's specific directive syntax for mod_rewrite, mod_headers, and mod_deflate, and a small typo can break your entire site or silently fail to apply. This generator produces syntactically correct rules for common needs: forcing HTTPS, enabling Gzip compression, setting browser caching headers, adding security headers, custom error pages, and 301/302 redirects.

This is particularly useful for developers and site owners managing Apache-hosted sites (a large share of shared hosting providers run Apache) who need standard optimizations and security hardening without deep Apache configuration expertise.

How to generate a .htaccess file

  1. 1

    Select the rules you need — toggle HTTPS redirect, Gzip compression, browser caching, security headers, custom error pages, or specific redirects

  2. 2

    Configure the details — set redirect URLs, cache durations, or error page paths as needed

  3. 3

    Review the generated file — the .htaccess content updates live as you adjust settings

  4. 4

    Copy or download — copy the text or download the .htaccess file directly

  5. 5

    Upload to your server — place the file in your site's root directory (or the relevant subdirectory) via FTP or your hosting file manager

When to use a .htaccess generator

Forcing HTTPS

Redirect all HTTP traffic to HTTPS to ensure encrypted connections and avoid mixed-content warnings.

Improving page speed

Enable Gzip compression and browser caching headers to reduce load times for returning visitors.

Hardening security

Add security headers like X-Frame-Options or X-Content-Type-Options to reduce common attack surfaces.

Managing URL changes

Set up 301 redirects when moving or renaming pages, preserving SEO value from the old URL.

Custom error pages

Serve a branded 404 or 500 error page instead of Apache's default.

Why use Pixvert's .htaccess generator?

  • Correct Apache syntax: avoids typos in mod_rewrite, mod_headers, and mod_deflate directives
  • Covers common needs: HTTPS redirect, caching, compression, security headers, and redirects in one tool
  • 100% local and private: your configuration choices are processed entirely in your browser
  • Free, instant, no signup: generate as many configurations as you need

Frequently Asked Questions

Where do I put the generated .htaccess file?

Upload it to the root directory of your website via FTP or your hosting control panel's file manager. Rules apply to that directory and all subdirectories unless overridden.

Will this work on any web server?

No, .htaccess is specific to the Apache web server (and Apache-compatible setups like LiteSpeed). Nginx and other servers use a different configuration syntax entirely.

Is my configuration data sent to a server?

No, the file is generated entirely in your browser based on the options you select. Nothing is transmitted or stored.

Can uploading a bad .htaccess file break my site?

Yes, a syntax error in .htaccess can cause a server error on your entire site. Always keep a backup of your current file before replacing it, and test after uploading.

Do I need special server permissions to use .htaccess?

Your hosting provider needs to allow .htaccess overrides (AllowOverride) for the directives to take effect — this is enabled by default on most shared hosting.

Can I combine multiple rules in one file?

Yes, select as many options as you need — the generator combines them into a single, correctly ordered .htaccess file.

Related Tools

Ad