Using Apache environment variables in .htaccess

In a previous post I talked about using environment variables to make your life easier when developing on multiple servers. In this post I will talk about how to use these variables in your .htaccess file.

Why .htaccess?

You may want some rules specific to different servers, maybe you want to hide certain paths on your live server, or perhaps you want to use a different robots.txt file. Below is a rule I’ve used to server a different robots file on a live server.

RewriteCond %{ENV:TESTSERVER} !yes
RewriteCond %{REQUEST_URI} robots.txt
RewriteRule (.*) robots.txt.block
  • Is the environment variable ‘TESTSERVER’ NOT equal to ‘yes’?
Read the rest