0

I have this .htaccess file inside DOCUMENT_ROOT where it checks for the existence of a file, maintenance.enable and serves maintenance.html if it is present:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    # This portion checks for the presence of maintenance.enable to toggle
    # maintenance mode
    RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
    RewriteCond %{DOCUMENT_ROOT}/maintenance.enable -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteRule ^.*$ /maintenance.html [R=503,L]
    ErrorDocument 503 /maintenance.html
    Header Set Cache-Control "max-age=0, no-store"

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

However, it doesn't seem to work outside DOCUMENT_ROOT. For example, considering I have a folder structure like this:

document_root/
  .htaccess
  index.php
  maintenance.html
  maintenance.enable
  test/
     .htaccess
     index.php
     maintenance.enable
     maintenance.html
outside_document_root/
   .htaccess
   index.php
   maintenance.html
   maintenance.enable

The folder outside_document_root is defined as an alias in the conf file.

FrancisV
  • 1,766
  • 3
  • 16
  • 18

1 Answers1

1

At first, you should not use .htaccess at all if you have access to configuration files as it slows down Apache. You could have all these settings inside the configuration file instead.

Configuration in .htaccess applies to the folder and it's sub-folders. You should have this <IfModule mod_rewrite.c> block inside the <virtualHost> directive to apply it on the whole VirtualHost including the folder defined by an alias.

If you prefer use .htaccessanyway, you can replace the %{DOCUMENT_ROOT} with the absolute filesystem path to the file.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129