Setting up and Using Environments with htaccess

Sep 11, 2014 10:13 · 109 words · 1 minute read drupal htaccess

This .htaccess snippet does the following:

  1. Create two environments called staging and development based on the host name
  2. Set up ht authentication only on the stage server (Deny from env=staging)
  3. Rewrite all requests to the main domain ( if we’re not on either the development nor staging environment and the host doesn’t already equal the main domain

    AuthName „Staging Server” AuthType Basic AuthUserFile /var/sites/mysite/.htpasswd AuthGroupFile /dev/null require valid-user

    SetEnvIf Host env=staging SetEnvIf Host env=development

    Order Allow,Deny Allow from all Deny from env=staging

    Satisfy Any

    RewriteBase /

    RewriteCond %{ENV:env} !development RewriteCond %{ENV:env} !staging RewriteCond %{HTTP_HOST} !^$ [NC] RewriteCond %{HTTP_HOST} !^$ [NC] RewriteRule ^(.*)$ [R=301,L]

On github: