.htaccess Generator
Generate production-ready Apache web server configuration rules for HTTPS redirection, Gzip compression, browser caching, and directory security.
Configuration Options
Redirect all HTTP traffic to secure HTTPS using a permanent 301 redirect.
Prevent visitors from listing files in directories without index pages.
Compress HTML, CSS, JavaScript, and SVG to reduce transfer payload by 60-80%.
Consolidate duplicate domain canonicalization for search engine indexing.
Show a custom HTML error page for missing URLs instead of default server errors.
Instruct visitors' browsers to cache static assets for faster repeat visits.
# ============================================
# .htaccess Generated by WebsiteHoste.com
# ============================================
# --- Force HTTPS/SSL ---
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# --- Redirect www to non-www ---
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# --- Disable Directory Browsing ---
Options -Indexes
# --- Enable Gzip Compression ---
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/woff
AddOutputFilterByType DEFLATE font/woff2
</IfModule>
# --- Browser Cache-Control Headers ---
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 2592000 seconds"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/css "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(css|js|jpg|jpeg|png|gif|webp|svg|woff|woff2|ttf|otf|ico)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "no-cache, no-store, must-revalidate"
</FilesMatch>
</IfModule>
What Is an .htaccess File? A Complete Guide for Webmasters
The .htaccess file (short for "hypertext access") is one of the most powerful configuration files available to website administrators running Apache web servers. This small but mighty plain-text file sits in the root directory of your website and controls everything from URL redirection and security policies to performance optimization and access control — all without requiring you to modify the main Apache server configuration or restart the web server.
Where to Place Your .htaccess File
The correct location for your primary .htaccess file depends on your hosting setup. On most cPanel-based shared hosting providers, you should place it inside the public_html directory (also sometimes called www or htdocs). This is the document root — the top-level folder from which Apache serves your website files.
Step-by-Step: Adding .htaccess via cPanel File Manager
- Log in to your hosting cPanel dashboard and open the File Manager application.
- Navigate to the
public_htmldirectory (your website root). - Click Settings in the top-right corner and check "Show Hidden Files (dotfiles)" — this is essential because files starting with a dot are hidden by default.
- If an
.htaccessfile already exists, right-click and choose Edit. If not, create a new file named exactly.htaccess(with the leading dot, no file extension). - Paste your generated rules, save the file, and test your website immediately to confirm the rules are working.
Frequently Asked Questions
Related Guides
More Webmaster Utilities
Robots.txt Builder
Crawl rules & AI bot blocking
SPF Record Generator
Authorised senders & lookup count
DMARC Record Generator
Spoofing policy & reports
Hosting Calculator
Storage, bandwidth & tier estimates
Meta Tag Generator
Live SERP & OpenGraph card previews
Schema Generator
JSON-LD rich snippet generators