Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

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!
  • 2
1 Solution
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.

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.

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now