מחולל .htaccess

צור Apache htaccess

הגדרות בסיסיות

אבטחה

ביצועים

דפי שגיאה

הפניות

.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

שאלות נפוצות

מה זה .htaccess?
.htaccess הוא קובץ תצורה של Apache ששולט בהפניות URL, אבטחה, מטמון וכללי גישה לספריות וקבצים באתר שלכם.
האם אני צריך .htaccess לכל השרתים?
לא, .htaccess ספציפי ל-Apache. Nginx משתמש ב-nginx.conf, IIS משתמש ב-web.config. הרבה מארחים מודרניים משתמשים ב-Nginx, בדקו את סוג השרת שלכם.
לאילו שימושים נפוצים משתמשים ב-.htaccess?
הפניות URL (www ל-בלי-www), אכיפת HTTPS, דפי שגיאה מותאמים, הגנת hotlink, הגנת סיסמה, כותרות מטמון, חסימת בוטים.