URL and Directory handling

Hi all,

This is more of a conceptual question than actual syntax or the like.

I'm currently revising an application which should contain one documentroot for each user. The catch is, the application should connect to a user specific backend database based on who's logging in.

My thoughts are the following:

URL name will be something like:  http://application.example.com/user (One DocumentRoot and the application's config file, config.php for argument sake, will reside here.)

Would my best bet be to use mod_env and SetEnv to grab the /(user) portion of the URL and then stick to my script specific engine to direct them to the user specific config file, based somewhere else on the filesystem? (At this point, it's not Apache's responsibility, it's at the application layer.)

Also, how about handling for URLs where a /user does not exist. Such as http://application.example.com/joebob (user joebob doesn't exist, I wish to redirect them), I'm assuming that's also best to do from an application level?

Thank you for your insight!
Who is Participating?
I'd  symlink all user directories to the document root itself (ln -s . user1; ln -s . user2 and so on) and let the index.php or wahtever figure out the user part of the URL (the environment var SCRIPT_NAME for instance) so you can decide based on that the DB connection.
why not using the mod_userdir from Apache?:


is a consitent way of achieving what you want.  

For error handling you could just define the page to show for 404 error code, something like this in your httpd.conf:

ErrorDocument 404 /errordoc-404.html

stevefNYCAuthor Commented:

Because /foo /bar /joebob should all share the same document root. I need the /user portion of the URL to pass to an environment variable in one of the scripts to determine which database to connect to.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.