Skip to content

Instantly share code, notes, and snippets.

@mucahitnezir
Last active August 21, 2023 01:11
Show Gist options
  • Save mucahitnezir/774ab0b688018eb10217b81c4903f552 to your computer and use it in GitHub Desktop.
Save mucahitnezir/774ab0b688018eb10217b81c4903f552 to your computer and use it in GitHub Desktop.
General .htaccess file for gzip/deflate compression and redirecting both of www and ssl(https). Needed modules in httpd.conf: deflate_module(modules/mod_deflate.so), (expires_module modules/mod_expires.so), (headers_module modules/mod_headers.so), (rewrite_module modules/mod_rewrite.so)
## KEEP-ALIVE ##
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
## KEEP-ALIVE ##
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 3 days"
</IfModule>
## EXPIRES CACHING ##
## GZIP COMPRESSION ##
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
## GZIP COMPRESSION ##
## SSL & WWW REDIRECTION ##
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.yoursitedomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.yoursitedomain.com/$1 [L,R=301]
</IfModule>
## SSL & WWW REDIRECTION ##
## DEFAULT REWRITE RULE ##
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\\.php|resources|robots\\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
## DEFAULT REWRITE RULE ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment