Merhaba arkadaşlar kendimin kullandığı ve her zaman işime yarayan arama motorlarına göre güncellenmiş dosyamı paylaşıyorum. Kendize göre editleyip kullanabilirsin. Umarım yardımcı olur.
# ============================================
# CMS - SEO & Performance .htaccess
# ============================================
# --- HTTPS Zorla ---
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# --- www → non-www ---
RewriteCond %{HTTP_HOST} ^www\.siteadresin\.com [NC]
RewriteRule ^(.*)$ https://siteadresin.com/$1 [L,R=301]
# --- Trailing Slash (SEO) ---
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} \.[a-zA-Z]{2,}$
RewriteRule ^(.*)$ /$1/ [L,R=301]
# --- Klasör index dosyaları ---
DirectoryIndex index.php index.html
# --- 404 Hata Sayfası ---
ErrorDocument 404 /404.php
# --- Gzip Sıkıştırma ---
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/json
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-opentype
</IfModule>
# --- Tarayıcı Önbellekleme ---
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 0 seconds"
ExpiresByType text/xml "access plus 0 seconds"
ExpiresByType application/json "access plus 0 seconds"
ExpiresByType application/xml "access plus 0 seconds"
ExpiresByType text/css "access plus 1 year"
ExpiresByType text/javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType application/x-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 image/x-icon "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/opentype "access plus 1 year"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
</IfModule>
# --- Cache-Control Headers ---
<IfModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|webp|svg|woff|woff2|ttf|otf|eot)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public, max-age=31536000, immutable"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "public, max-age=2678400"
</filesMatch>
<filesMatch "\.(html|htm|php)$">
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "0"
</filesMatch>
</IfModule>
# --- SEO Header'ları ---
<IfModule mod_headers.c>
Header set X-Content-Type-Options "nosniff"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy "strict-origin-when-cross-origin"
Header set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>
# --- ETag Kaldır (Cache提速) ---
<IfModule mod_headers.c>
Header unset ETag
</IfModule>
FileETag None
# --- Güvenlik: Hassas Dosyaları Engelle ---
<FilesMatch "^(db\.php|config\.php|functions\.php|content\.php|send_mail\.php|license\.php|\.env|composer\.(json|lock))$">
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order Allow,Deny
Deny from all
</IfModule>
</FilesMatch>
# --- Klasör Listelemeyi Engelle ---
Options -Indexes
# --- .git, .env, backup dosyalarını engelle ---
<IfModule mod_rewrite.c>
RewriteRule ^\.git - [F,L]
RewriteRule ^\.env - [F,L]
RewriteRule ^\.htaccess$ - [F,L]
RewriteRule \.(sql|bak|old|log|ini|sh)$ - [F,L]
</IfModule>
# --- PHP Eş Zamanlılıksız ---
<IfModule mod_php7.c>
php_flag display_startup_errors off
php_flag display_errors off
php_flag log_errors on
</IfModule>
<IfModule mod_php.c>
php_flag display_startup_errors off
php_flag display_errors off
php_flag log_errors on
</IfModule>
# --- Resource Limits ---
<IfModule mod_php7.c>
php_value max_execution_time 60
php_value memory_limit 256M
php_value post_max_size 20M
php_value upload_max_filesize 10M
</IfModule>
<IfModule mod_php.c>
php_value max_execution_time 60
php_value memory_limit 256M
php_value post_max_size 20M
php_value upload_max_filesize 10M
</IfModule>