Last active
April 13, 2021 16:07
Revisions
-
Jamiewarb revised this gist
Nov 30, 2017 . 1 changed file with 53 additions and 23 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,29 +1,59 @@ RewriteEngine On RewriteBase / ## Whitelisting + Maintenance # Whitelist IPs to a single page, redirect all else RewriteCond %{REMOTE_ADDR} !^000\.000\.000\.000 RewriteCond %{REMOTE_ADDR} !^000\.000\.000\.000 RewriteCond %{REQUEST_URI} ^/whitelist-me.php$ RewriteRule ^(.*)$ https://domain.com [R=307,L] # Maintenance page with whitelisting IP and some assets used on the page RewriteCond %{REMOTE_ADDR} !^000\.000\.000\.000 RewriteCond %{REQUEST_URI} !^/maintenance\.php$ # Allow a specific requ RewriteCond %{REQUEST_URI} !^/company-logo.png$ [NC] # Allow a series of filetypes RewriteCond %{REQUEST_URI} !\.(css|jpe?g?|png|gif|woff|ttf) [NC] RewriteRule ^(.*)$ https://www.domain.com/maintenance.php [R=307,L] ## Protocol Redirects # non-www to www redirect RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301] # www to non-www redirect RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] # http to https redirect RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] # https to http redirect RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ####### # http to https redirect && www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] # https to http redirect && www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ## Removing file extension RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php -
Jamiewarb created this gist
Apr 26, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # non-www to www redirect RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301] # www to non-www redirect RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] # http to https redirect RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] # https to http redirect RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] ####### # http to https redirect && www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] # https to http redirect && www to non-www RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]