Skip to content

Instantly share code, notes, and snippets.

@davidalexander
Created July 16, 2011 20:47
Show Gist options
  • Save davidalexander/1086773 to your computer and use it in GitHub Desktop.
Save davidalexander/1086773 to your computer and use it in GitHub Desktop.
.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