Last active
May 17, 2021 14:10
-
-
Save klickreflex/779683dcc62a7776dcab to your computer and use it in GitHub Desktop.
Setting up and Using Environments with htaccess
This file contains 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
# 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 (www.mysite.com) 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 mysite.klickreflex.com env=staging | |
SetEnvIf Host mysite.dev env=development | |
Order Allow,Deny | |
Allow from all | |
Deny from env=staging | |
Satisfy Any | |
<IfModule mod_rewrite.c> | |
RewriteBase / | |
RewriteCond %{ENV:env} !development | |
RewriteCond %{ENV:env} !staging | |
RewriteCond %{HTTP_HOST} !^mysite\.dev$ [NC] | |
RewriteCond %{HTTP_HOST} !^www.mysite\.com$ [NC] | |
RewriteRule ^(.*)$ http://www.mysite.com [R=301,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment