I’m trying to make a script to put on all my pages on my site saying if so and so file exist in the root directory (“/”) it will auto redirect to it and if the file isn’t there it does nothing.
I’m using this so i can set up a maintenance mode for the site so i can take it down while im working on it. I already have made the maintenance page, I just don’t know how to set up the script. The file name is maintenance.html and I only want it to be in the root file. I don’t want to have to upload it to every directory to take the site down.
The file url would be http://domain.tld/maintenance.html and the script would go if the file is there and redirect to that file else if it’s not there don’t redirect.
I know the redirect code is (in HTML)
<meta HTTP-EQUIV="REFRESH" content="0; url=http://domain.tld">
A set of redirection rules for your webserver is what you need, methinks. If you’re running Apache,
mod_rewriteis the magic word, if you’re running something else, well, then, I wouldn’t know the magic word, but something similar exists for most servers, if not all.But, using Apache’s brilliant
mod_rewrite, to redirect ALL traffic to a set page or address, e.g. during maintenance, is as simple as:Where should these instructions be, you ask? Well, since it’s a temporary thing, the most logical would be in a
.htaccessfile in your webroot. But it’s also possible to include the same in your servers/virtualhosts global configuration, which for a permanent ruleset would make sense from an optimization aspect.To disable the redirection, it’s enough to comment out either the
RewriteEngine onstatement, or theRedirectRulestatement. You could also rename your.htaccessto something else or delete it.