I simply got a strange idea concerning how to configure atmosphere-dependent parameters. Kind of like parameters you'll find in Rails' config/database.yml

During my current project I personally use PHP and Litespeed Web Server (although the same technique is applicable to PHP + Apache), and that i thought... 'why not use mod_rewrite with this?A. I've separate virtual hosts configs for every env (development/production right now)

Things I have finally is:

RewriteRule (.*) $1 [env=development:1]

for that development atmosphere vhost. But let's say it will likely be something similar to this?

RewriteRule (.*) $1 [env=development:1,env=mysql_host:localhost,env=mysql_port:3306,env=mysql_user:root,env=mysql_pass:,env=mysql_db:mydbname]

Wouldn't it seem sensible or may cause some problems? What is your opinion?

I do not believe rewrite rules really are a particularly intuitive spot to put configuration information like this. Maybe I'm misunderstanding something, but may be the only distinction between the expansion, staging, and production conditions the database connection? Often the code can also be different (at least one time changes are created), and so if you're utilizing a revision control system, It may well be a better idea to possess a template configuration file (database.cfg.template) that you simply copy (and inform your revision control system to disregard) and modify (to database.cfg). Then it is apparent where this post is.

You are right -- it is a wierd idea.

IMO, this can be a really bad use for mod_rewrite. True, the configuration information goes using the machine, as opposed to the codebase (an error I see people make constantly), however it does not always belong using the webserver configuration, either.

I would suggest a configuration file that's not handled by version control.

If you wish to set the atmosphere within the vhost that you can do something similar to

php_value ENV "development"

After which see clearly in the $_SERVER array

To begin with, if you are not really altering the URL, avoid using $1 because the alternative, only use a dash. According to the paperwork:

A dash signifies that no substitution ought to be carried out (the present path is passed through untouched). This really is used whenever a flag (see below) must be used without altering the road.

However ,, I believe the reply is mod_env. SetEnv directives might be placed in your <VirtualHost> blocks, staying away from the unwanted RewriteRule foo.

The very best and just place best places to define current atmosphere is boostrap.

Take a look at symfony or agavi bootstraping files.