URL and Directory handling

Posted on 2007-07-30
Last Modified: 2013-12-16
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: (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 (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!
Question by:stevefNYC
    LVL 7

    Expert Comment

    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

    LVL 3

    Author Comment


    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.

    LVL 7

    Accepted Solution

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now