Last active
February 19, 2018 09:41
-
-
Save grand-lotus-iroh/66dd46205c41ceee83130b78c4091e3d to your computer and use it in GitHub Desktop.
Powerful .htaccess snippets that require RewriteEngine On at the very top
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Default force to HTTPS for all traffic | |
RewriteCond %{HTTPS} !=on | |
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
# Force SSL / HTTPS Redirection v2 | |
Options +FollowSymLinks | |
Options -Indexes | |
Options -MultiViews | |
RewriteCond %{HTTPS} off | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
# Force non-www: | |
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC] | |
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301] | |
# Deny and than redirect every IP that is not on the whitelist | |
# Protect a specific directy by creating another .htaccess file ^ _ ^ | |
order deny,allow | |
allow from 192.168.1.420 | |
deny from all | |
ErrorDocument 403 https://redirect-visitor.com | |
# Prevent viewing of .htaccess file. | |
<Files .htaccess> | |
order allow,deny | |
deny from all | |
</Files> | |
# Optimize website, enable compression gzip | |
<ifModule mod_gzip.c> | |
mod_gzip_on Yes | |
mod_gzip_dechunk Yes | |
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$ | |
mod_gzip_item_include handler ^cgi-script$ | |
mod_gzip_item_include mime ^text/.* | |
mod_gzip_item_include mime ^application/x-javascript.* | |
mod_gzip_item_exclude mime ^image/.* | |
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* | |
</ifModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment