Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.htaccess Environments
# http://thenerdary.net/articles/entry/htaccess-environments
RewriteEngine On
RewriteBase /
### SET UP ENVIORNMENTS ###
# Default to master
RewriteRule .* - [E=ENVIRONMENT:master]
# is localhost or ends with
RewriteCond %{SERVER_NAME} localhost [OR]
RewriteCond %{SERVER_NAME} .dev$ [OR]
RewriteCond %{SERVER_NAME} .local$
RewriteRule .* - [E=ENVIRONMENT:dev]
# starts with
RewriteCond %{SERVER_NAME} ^staging.
RewriteRule .* - [E=ENVIRONMENT:staging]
### DEV ###
RewriteCond %{ENV:ENVIRONMENT} dev
# Do this ...
### STAGING ###
RewriteCond %{ENV:ENVIRONMENT} staging
# Do this ...
### MASTER ###
RewriteCond %{ENV:ENVIRONMENT} master
# Do this ...
### USE IN SCRIPTS ###
# php: $_SERVER['ENVIRONMENT']
# ruby: ENV['ENVIRONMENT']
# ruby (on rails): request.environment
# python: os.environ['ENVIRONMENT']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment