Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Serve user sites without the tilde in the URL Internet
I have several users on one of my 10.2 boxes. They all want to publish their web pages, but don't like the idea of having to type http://mydomain.com/~user/. So what I did was create a symbolic link from their Sites folder to the web root, /Library/WebServer/Documents/.

I name the symbolic link as their short user name. When they want to access their personal web site, they only have to type http://mydomain.com/user/. For those of you wanting to know how to make the link, just open a Terminal and type:
 % ln -s /Users/username/Sites  /Library/WebServer/Documents/username
Replace 'username' with the user's short user name, obviously. That's all you need to do; the users can now access their sites without typing the tilde. My users like it, so I thought maybe one of you may find it useful.
    •    
  • Currently 4.00 / 5
  You rated: 5 / 5 (2 votes cast)
 
[9,886 views]  

Serve user sites without the tilde in the URL | 5 comments | Create New Account
Click here to return to the 'Serve user sites without the tilde in the URL' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
mod_rewrite could also be used
Authored by: awk on Oct 28, '02 12:54:32PM

It's also possible to do this automatically with some mod_rewrite mumbo-jumo, just add this to the end of your /etc/httpd/httpd.conf:

RewriteEngine on RewriteCond %{REQUEST_URI} ^/+([a-z][a-z0-9]+)(/+(.*)|$) RewriteCond /Users/%1/Sites -d RewriteRule .* /Users/%1/Sites/%3

It checks for any request matching /xyz, /xyz/, /xyz/other/stuff, where xyz is any letters and numbers. Then it checks that the directory /Users/xyz/Sites exists. If so it rewrites the request to match that directory.

I don't know the impact this would have on performance, but it works okay for me! (Actually on my machine I have it do a redirect to /~xyz/ but the idea is similar.)



[ Reply to This | # ]
mod_alias should also work
Authored by: dukeku on Oct 28, '02 08:09:30PM

I'm pretty sure you could just use Alias (if mod_alias is installed.)

It would be something like this in a .htaccess file or in httpd.conf (don\'t hold me to this, I\'m doing this entirely from memory, and it probably is wrong)

Alias /Users/name/Sites /name

The actual format is in the Apache manual, under mod_alias. That would make it so that when someone requests http://1.2.3.4/name/, it would map that to /Users/name/Sites. Something like that. I would look in the Apache manual on it before trying it though.



[ Reply to This | # ]
mod_alias should also work
Authored by: Vhalkyrie on Oct 30, '02 12:31:57AM

Yes, the preferred way to do this is through apache with an alias. Go to /private/etc/httpd/users. In that directory should be the individual conf files for each user. Open the files and add the line:

Alias /name "/Users/name/Sites"

Where name is the user's name. Restart apache.

If you have a small number of users, edit by hand. If you have a large number of users, script it! These files are automatically created when you add a new user, so there's probably a way to edit it at the source so you don't have to do this every time you add a new user.



[ Reply to This | # ]
mod_alias should also work
Authored by: Schwie on Feb 14, '04 12:50:34PM
From MacWorld:

Banish the Tilde from Users' Site Names

With OS X's built-in Personal Web Sharing (found in the Sharing preference pane), every user on your Mac can have a personal Web site that others can access at a URL such as http://your.ip.number/~user_name.

If you don't like having the tilde in the URL, however, you can easily remove it with Terminal and an admin password.

Open a Terminal window, and then type

cd /etc/httpd/users

to switch to the directory that Apache (the built-in Web server) uses to manage the user sites. If you're unsure of your users' short names, type ls to see a list of the available configuration files. Say you want to modify the settings for a user named Alice:
type sudo pico alice.conf
and enter your admin password when prompted to do so. Once the file is open, type the following above the first line (the one that begins with

Alias /alice "/Users/alice/Sites".

This Alias command acts just like an alias file in the Finder -- it tells Apache that someone looking for a page at the /alice URL should be sent to Alice's Sites folder instead.

Once you've added the line, press control-X to exit, and then press Y when pico asks if you'd like to save the modified buffer -- this will write your changes to the file.

Return to the Sharing preference pane, and turn the Personal Web Sharing feature off and then back on. This restarts Apache, which will then read the modified configuration. From now on, you can skip the tilde and just type http://your.ip.address/alice to get to Alice's Web site. Repeat this process for any other user URL you'd like to modify.



[ Reply to This | # ]

user.mydomain.com?
Authored by: mclbruce on Oct 30, '02 07:13:27PM

What about substituting user.mydomain.com for mydomain.com/~user/ ? It would be a nice hack, er, modification. Some ISP's are starting to use username.home.myisp.com for member web sites.



[ Reply to This | # ]