title: Use PHP to Dynamically Add To .htaccess File?
body: <p>What I am trying to do is automate the process of going live with websites.  These websites are all dynamically created using htaccess, so here is an example:</p>
  
  <pre><code>RewriteCond %{ENV:REDIRECT_STATUS} ^$
  RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
  RewriteRule ^(.*)$ /folder%{REQUEST_URI}?%{QUERY_STRING} [QSA,L]
  </code></pre>
  
  <p>What I do is add a domain alias for <em>domain.com</em>, and then point it to my server IP and the htaccess file makes it view what is in the /folder.</p>
  
  <p>It works fine but we are planning to have hundreds of websites and adding that snippet of code to the htaccess manually can get pretty annoying.  Since all I am changing is <em>domain.com</em> and the <em>/folder</em>, is there a way to use PHP to dynamically add to the bottom of the .htaccess file if I create a form and tell it the domain and the folder, it will add it to the bottom of the htaccess file?</p>
  
  <p>That would save so much time.</p>
  
  <p>Thanks so much.</p>