Optimized Version htaccess for wordpress website
April 7, 2026 in WordPress
🔥 What Improved
- ✅ Single clean redirect (faster + SEO friendly)
- ✅ AI folder properly excluded
- ✅ No duplicate rewrite engine
- ✅ Better security
- ✅ Safer structure
RewriteOptions inherit
DirectoryIndex index.php
# ======================================
# 🔁 Rewrite Rules (Clean + Optimized)
# ======================================
<IfModule mod_rewrite.c>
RewriteEngine On
# ✅ Exclude AI folder
RewriteRule ^ai/ - [L]
# ✅ Force HTTPS + non-www in ONE step
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\.soatechnology\.net [NC]
RewriteRule ^ https://soatechnology.net%{REQUEST_URI} [L,R=301]
# ✅ Preserve Authorization Header
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# ✅ WordPress Rules
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# ======================================
# ⚡ Compression
# ======================================
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>
# ======================================
# ⚡ Caching
# ======================================
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/webp "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
# ======================================
# 🔒 Security
# ======================================
Options -Indexes
<FilesMatch "(wp-config\.php|\.htaccess)">
Require all denied
</FilesMatch>
# ======================================
# 🔐 Security Headers
# ======================================
<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"
</IfModule>
# ======================================
# ⚠️ Login Redirect (Use carefully)
# ======================================
RedirectMatch "^/wp-login/?" /login