Forum Moderators: phranque

Message Too Old, No Replies

Apache DocumentRoot

DocumentRoot redirect problem

         

zenopopovici

5:14 pm on Oct 3, 2006 (gmt 0)

10+ Year Member



Hi guys,

I'm realy not that good at regexp or Rewrite Engine.

I have the following structure:


/home/ftphome/users/user1/html
/home/ftphome/users/user2/html
/home/ftphome/users/user3/html

The users are not system users (security reasons) but are fetched from a MYSQL database.

I'm using:


<VirtualHost 1.2.3>
ServerAdmin webmaster@myserver.com
DocumentRoot /home/ftphome/users/
ServerName webspace.myserver.com
#Custom Redirect to noindex if folder has no index file
<Directory /home/ftphome/users/*>
Options All +Includes
AllowOverride None
Options -Indexes
ErrorDocument 403 /errors/noindex.php
Order allow,deny
Allow from all
</Directory>
ErrorLog logs/webspace_error_log
CustomLog logs/webspace_access_log combined
#Custom Error Messages
ErrorDocument 400 /errors/badrequest.php
ErrorDocument 401 /errors/authorize.php
ErrorDocument 403 /errors/forbidden.php
ErrorDocument 404 /errors/notfound.php
ErrorDocument 500 /errors/servererror.php
</VirtualHost>

Right now the user is accessing:
http://webspace.myserver.com/user1/html

to see his personal webspace.
A index.php file placed in / redirects the user in the /html/ folder.

Is there any method to make the document root point to:

/home/ftphome/users/*/html/

Or use an alias, rewrite, redirect to make the path be:

http://webspace.myserver.com/user1/

and point to
/home/ftphome/users/user1/html/

For ALL users?

Cheers,
Zeno.

jdMorgan

4:37 pm on Oct 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem with this approach is that mod_rewrite or mod_alias needs some way to know that what it is looking at is a "username." Otherwise, you end up rewriting or aliasing *everything* to a user directory. This might be OK, but consider such things as robots.txt, /w3c/p3p.xml, site-wide logos, headers, and scripts, and other "common" files that you may want to share across all users.

This problem would be easy if the users always requested /user/html, because then detecting that a rewrite or alias is needed would be easy -- just look for that "html" in the requested URL path. But that would look "ugly" and usability would suffer. So how do you decide whether to invoke a rewrite or alias using your current URL structure? I don't see a good way to do it.

Consider using one of three possible methods to make this determination easier:

  • Define subdomains for each user: i.e. http://username.example.com/ as the user's base directory. Each subdomain (except "www") could then be easily mapped to /users/html/username or any other path you choose.

  • Tag each username-related URL, i.e. use URLs like http://www.example.com/user-username. Here the "user-" prefix can be used to tell mod_rewrite or mod_alias to take action.

  • Use the built-in capability of Apache mod_userdir, where URLs look like http://www.example.com/~user (here again. we're tagging the URLs, this time with "~".

    The key is to provide the server with an easy way of detecting URLs that it needs to change versus those that it should leave alone.

    Also, there is no need to redirect and you should avoid it, as this exposes the "real" user directory paths to users, inviting security problems. Instead, use internal rewrites or aliases. These change the server filepath associated with a requested URL, but do not change the URL or notify the client (browser) that the URL has changed. The action is therefore transparent to users and search engine spiders alike.

    I suggest you research this for several days before committing yourself to any specific approach; You'll have to live with the decision for a long time, and any later changes would likely upset your users and risk losing much of your current search engine rankings/listings.

    Jim

  • zenopopovici

    6:47 pm on Oct 6, 2006 (gmt 0)

    10+ Year Member



    Thanks Jim!

    I thought it needed an identifier ... thanks a lot for making it clear for me :)

    I think I will use ~.

    Thanks,
    Zeno.