.htaccess Generator

100% Free · Client-Side

Generate secure and optimized .htaccess files for your Apache server. Handle redirects, security headers, caching, and more with ease.

Configuration

Canonical & Global Redirects

Redirect all HTTP traffic to HTTPS

Custom Redirect Builder

Security Hardening

Prevent users from seeing file lists if index.html is missing

Block access to .env, .git, .yml, .config files

Prevent self-access/reading of the .htaccess file

Performance & SEO

Enable Gzip

Compress text/css/js

Leverage Cache

Set expires headers

Required if you are using WordPress on your server.

.htaccess Preview

Ready for production deployment

# Generated by CampaignMorph .htaccess Tool
# Date: 4/12/2026


  RewriteEngine On
  RewriteBase /

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

  # Custom Redirect 301
  Redirect 301 /old-page /new-page



# Disable Directory Browsing
Options -Indexes

# Protect .env, .git, and config files

  Order allow,deny
  Deny from all


# Protect .htaccess file

  Order allow,deny
  Deny from all


# Custom 404 Error Page
ErrorDocument 404 /404.html

# Gzip Compression

  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript


# Browser Caching (Expires Headers)

  ExpiresActive On
  ExpiresDefault "access plus 1 month"
  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 text/css "access plus 1 month"
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/x-javascript "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 year"

Attention: Improper .htaccess settings can cause 500 Internal Server Errors. Always backup your existing file before replacing it. We recommend starting with "Force HTTPS" and adding rules one by one.

Mastering Apache Configuration

The .htaccess file is a powerful configuration tool for Apache web servers. It allows you to control redirects, security, and performance at a per-directory level without needing to restart the server.

Why .htaccess Matters for SEO?

Canonicalization

Forcing a single version of your site (HTTPS/WWW) prevents duplicate content issues and consolidates your link juice.

Page Speed (LCP)

Enabling Gzip and Browser Caching via .htaccess directly improves Core Web Vital scores and ranking potential.

301 Redirects

Properly mapping old URLs to new ones preserves nearly 100% of the original page's SEO authority.

Security Headers

Setting X-Content-Type or CSP headers increases site trust and prevents malicious crawl-budget wastage.

How to Use .htaccess File?

1

Download or Copy

Generate your configuration and download the .htaccess file or copy the raw code.

2

Upload to Server

Using FTP or your cPanel File Manager, upload the file to the root directory (usually public_html).

3

Rename if Necessary

Ensure the file is named exactly ".htaccess" (including the leading dot).

4

Test Your Site

Try both HTTP and HTTPS versions of your site to ensure redirects are working as expected.

Frequently Asked Questions

1. Where should I place the .htaccess file?

To affect your entire website, place it in the root directory (usually /public_html or /www). To affect only a specific folder, place it within that folder.

2. Why can't I see the .htaccess file on my server?

Files starting with a dot are "hidden" by default in Linux/Unix systems. In your FTP client or File Manager, look for an option like "Show hidden files" or "Show dotfiles."

3. Can .htaccess speed up my website?

Yes! By enabling Gzip compression and leveraging browser caching, you reduce the amount of data transferred and allow visitors to store static assets locally, significantly improving load times.

4. What should I do if my site crashes after an update?

Don't panic! Simply delete the .htaccess file or rename it to .htaccess.bak to restore site access. Then, review the code and add rules one by one to find the conflict.

We respect your privacy

We use cookies to analyze site traffic and personalize your experience. By clicking "Accept", you agree to our use of cookies. You can always choose to continue without tracking by clicking "Reject".