.htaccess Generator
Generate .htaccess rules for HTTPS, redirects, caching, compression and more.
.htaccess
# Generated by Utylo.com
# Force HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
# 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/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/svg+xml "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/javascript "access 1 month"
</IfModule>
# Custom Error Pages
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
Key Features
- Generates .htaccess rules for forcing HTTPS, www redirects, and custom error pages.
- Creates browser caching rules with appropriate expiry headers for different file types.
- Builds password protection (HTTP Basic Auth) entries for specific directories.
- Generates hotlink protection rules to prevent other sites from embedding your images.
- Outputs clean, commented .htaccess code ready to copy and deploy.
- Runs entirely in the browser — no server interaction needed.
Frequently Asked Questions
What is an .htaccess file?
An .htaccess file is a directory-level configuration file used by Apache web servers. It allows you to override server settings for redirects, security, caching, and URL rewriting without editing the main server configuration.
Will .htaccess rules work on Nginx servers?
No. .htaccess is an Apache-specific feature. Nginx uses a different configuration syntax in server block files. The rules generated by this tool apply only to Apache-based hosting.
How do I force HTTPS using .htaccess?
Select the 'Force HTTPS' option in the generator and copy the output redirect rule into your .htaccess file. The tool generates a standard mod_rewrite rule that redirects all HTTP traffic to HTTPS.