htaccess: set and use environment variables inside your htaccess

A while ago I learned how to set a variable in my .htaccess that can later on be user in PHP:



Something that I could not figure out was how to use the defined variable inside the htaccess. While searching for CORS implementation, I ran across this post on

There there is the answer to my question, how to set and get an environment variable in htaccess:

SetEnvIf Origin "^(.*\.example\.com)$" ORIGIN_SUB_DOMAIN=$1
<FilesMatch "\.woff$">
    Header set Access-Control-Allow-Origin "%{ORIGIN_SUB_DOMAIN}e" env=ORIGIN_SUB_DOMAIN

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

IMPORTANT! To be able to proceed, you need to solve the following simple math (so I know that you are a human) :-)

What is 12 + 10 ?
Please leave these two fields as-is: