Last active
May 24, 2018 09:53
-
-
Save mecmartini/41ae12fb14cf0be525b259c7d1dff154 to your computer and use it in GitHub Desktop.
Example of .htaccess environment conditionals
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
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
# SET UP DEFAULT ENVIORNMENT TO MASTER | |
RewriteRule .* - [E=ENVIRONMENT:master] | |
# SET UP ENVIORNMENT TO DEVELOP IF WE ARE ON localhost OR .dev OR .local | |
RewriteCond %{SERVER_NAME} localhost [OR] | |
RewriteCond %{SERVER_NAME} .dev$ [OR] | |
RewriteCond %{SERVER_NAME} .local$ | |
RewriteRule .* - [E=ENVIRONMENT:develop] | |
# SET UP ENVIORNMENT TO STAGE IF WE ARE ON stage. | |
RewriteCond %{SERVER_NAME} ^stage. | |
RewriteRule .* - [E=ENVIRONMENT:stage] | |
# DEVELOP | |
# ... | |
# STAGE | |
# ... | |
# Redirect HTTP to HTTPS only if environment is set to master | |
RewriteCond %{ENV:ENVIRONMENT} master | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment