Search code examples
apache.htaccesshttp-redirectdocument-rootapache-modules

.htaccess If file exists, set document root to subdirectory


I would like to use .htaccess to set a rule where if config.php exists then set root directory to / and if config.php does not exist, set root directory to /install.

How can this be done?

Thanks!


Solution

  • RewriteEngine on
    RewriteCond %{DOCUMENT_ROOT}/config.php !-f
    RewriteRule ^/?$ /install [L]
    

    This will set /install as your home dir if /config.php does not exist in your filesystem.