I am attempting to accomplish the next inside a .htaccess file, but can't appear to have it to operate...

  • if file ~/maintenance.htm is available, temporarily redirect to that particular file (R=302) and append the present query string (QSA), finish (l)
  • if maintenance.htm file is asked for (refresh by user) and is available, show the file, query string and finish (L, QSA)
  • it maintenance.htm file is asked for (refresh by user) and no more is available, redirect to index.php (R=301) and append the query string (QSA), finish (L)

The initial step is how it is going wrong, I can not appear to discover a method to check on whether personal files is available, that's not presently being asked for. I have been searching at lot of different things, also RewriteMaps, but can't appear to get at redirect from rewritemaps, or that's simply not obvious in my experience. For example basically write as basic perl script that inspections if your file is available, how do you obtain the derive from that to if you should redirect?

Thank you for any help/tips!

Maybe RewriteCond %{REQUEST_FILENAME} !-f will assist you to look for file existance

'-f' (is regular file) Goodies the TestString like a pathname and tests whether it is available, and it is a regular file.

See: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

I am unsure that which you have previously, but this will work. You had been most likely obtaining the 500 error while using the -f due to a internal redirect loop.

RewriteEngine on

RewriteCond %{REQUEST_URI} !/maintenance.htm
RewriteCond %{DOCUMENT_ROOT}/maintenance.htm -f
RewriteRule (.*) /maintenance.htm [L,R]

RewriteCond %{REQUEST_URI} /maintenance.htm
RewriteCond %{DOCUMENT_ROOT}/maintenance.htm !-f
RewriteRule (.*) /index.php [L,R=301]

Hope this can help.