Gerador .htaccess

Gerar Apache htaccess

Configurações Básicas

Segurança

Desempenho

Páginas de Erro

Redirecionamentos

.htaccess
# Generated by ToolNest .htaccess Generator
# 

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

# Default index file
DirectoryIndex index.php

# Disable directory listing
Options -Indexes

# Protect .htaccess
<Files .htaccess>
    Order allow,deny
    Deny from all
</Files>

# Block bad bots
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (bot|crawl|slurp|spider|mediapartners) [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot|bingbot|yandex|duckduckbot) [NC]
RewriteRule .* - [F,L]

# Enable Gzip compression
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
    AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
    AddOutputFilterByType DEFLATE application/json application/xml application/xhtml+xml
    AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf
</IfModule>

# Browser caching
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/html "access plus 3600 seconds"
    ExpiresByType text/css "access plus 2592000 seconds"
    ExpiresByType text/javascript "access plus 2592000 seconds"
    ExpiresByType application/javascript "access plus 2592000 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"
    ExpiresByType image/gif "access plus 2592000 seconds"
    ExpiresByType image/webp "access plus 2592000 seconds"
    ExpiresByType image/svg+xml "access plus 2592000 seconds"
    ExpiresByType font/woff2 "access plus 31536000 seconds"
</IfModule>

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

Perguntas Frequentes

O que é .htaccess?
.htaccess é um arquivo de configuração Apache que controla redirecionamentos URL, segurança, cache e regras de acesso para diretórios e arquivos do seu site.
Preciso de .htaccess para todos os servidores?
Não, .htaccess é específico do Apache. Nginx usa nginx.conf, IIS usa web.config. Muitos hosts modernos usam Nginx, verifique seu tipo de servidor.
Para que é comumente usado .htaccess?
Redirecionamentos URL (www para sem-www), forçar HTTPS, páginas de erro personalizadas, proteção hotlink, proteção por senha, cache, bloquear bots.