Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Depending on where I install my set of files, it seems like RewriteBase seems has to change accordingly if I install it in a subdirectory rather than at the www root.

For my configuration files, I use something like the following to allow for administrators to change the settings to suit their deployment environment.

$yaml = file_exists($yamldir) ? Spyc::YAMLLoad($yamldir) : array();
$default = array(
  'hostname' => '',
  'base_uri' => '/sub/',
  'mysql_host' => 'localhost',
  'mysql_username' => 'root',
  'mysql_password' => '',
  'schema_name' => 'schema1',
  'table_name' => 'table1'

$config = array_merge($default, $yaml);

The config.yml is then SVN or git ignored as to allow for maximum flexibility. It seems like the best way to do it.

Is there an equivalent for the .htaccess file, to read (or better yet, parse) a configuration file that may or may not exist?

Background information

My .htaccess needs are incidentally quite simple in this case:

RewriteEngine On
RewriteBase /sub

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php [L]

It would be probably for the best if I used a Rails-style public directory instead of having an effectively "open" www root, but I can take care of that as needed. Is the RewriteBase even necessary in my case? I'm not sure it is. Even so, I can think of cases in the future where I have a more elaborate .htaccess, where I would be hard-pressed to find a workaround for RewriteBase (or am I wrong in thinking this too?)

share|improve this question

You probably should use a custom script for doing the rewrite: - External Rewriting Program

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.