On my PHP site I would like to sometimes show a maintenance page to users. I know I can do this in PHP very easily but I would rather use an htaccess file, I think performance may be better this way. So what I am wanting to know is can I modify a htaccess file in PHP? If it is possible I am thinking either,
1 - Have to files and 1 will have the code below in it and the other will not, both files would contain my other htaccess stuff as well. Then php can rename these 2 files when I run an admin script to switch which file is shown, by changing it's name to .htaccess
2- Read the contents of the current .htaccess file and APPEND the code below into it, then also be able to remove it from the file if needed.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.php$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
My goal is to build an admin script that can have 1 click processing to change the maintenance page to show or not to show.
Please any sample code or tips on how to do this or if it is even possible to modify a .htaccess file from PHP