[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How to redirect /~username to /users/username?

Posted on 2003-03-26
8
Medium Priority
?
475 Views
Last Modified: 2010-03-04
I'm trying to setup Apache so that calls to site.com/~username can instead be site.com/users/username.
I've already got my users directories in /home/users/*, and the tilde works fine, but it really confuses people for some reason. Sigh.

Looking at mod_alias, it appears this should be possible, but for the life of me I can't get it right.

Thanks for your help!
0
Comment
Question by:mcdev
6 Comments
 

Accepted Solution

by:
brenthel3 earned 136 total points
ID: 8211164
Instead of mod_alias try mod_rewrite.


taken from:

"http://httpd.apache.org/docs/misc/rewriteguide.html"

In the example ruleset below we replace /~user by the canonical /u/user and fix a missing trailing slash for /u/user.

RewriteRule   ^/~([^/]+)/?(.*)    /u/$1/$2  [R]
RewriteRule   ^/([uge])/([^/]+)$  /$1/$2/   [R]
0
 

Expert Comment

by:brenthel3
ID: 8211626
Instead of mod_alias try mod_rewrite.


taken from:

"http://httpd.apache.org/docs/misc/rewriteguide.html"

In the example ruleset below we replace /~user by the canonical /u/user and fix a missing trailing slash for /u/user.

RewriteRule   ^/~([^/]+)/?(.*)    /u/$1/$2  [R]
RewriteRule   ^/([uge])/([^/]+)$  /$1/$2/   [R]
0
 
LVL 9

Assisted Solution

by:mglxxx
mglxxx earned 132 total points
ID: 8216255
Use mod_userdir.
See docs for the UserDir directive at
http://httpd.apache.org/docs-2.0/mod/mod_userdir.html#userdir
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
LVL 1

Author Comment

by:mcdev
ID: 8224686
Hello gentlemen.

Brenthel, you quoted word for word from the apache docs, which actually pertain to creating organized subdirectories for UserDir, but still using ~.

I'm able to get to the addresses using:
www.domain.com/~username
It's aliasing the ~ to /users/ that is the problem.

Here's my apache config so far:

UserDir /home/users/*

<Directory /home/users/*>
        AllowOverride FileInfo AuthConfig Limit
        Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    <Limit GET POST OPTIONS>
        Order allow,deny
        Allow from all
    </Limit>

<LimitExcept GET POST OPTIONS>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>
0
 

Expert Comment

by:brenthel3
ID: 8225654
yes i know i took that word for word, that's why i gave them credit.

to my understanding if you use mod_alias you have to write a block for each user and that does not make a lot of sense.

Alias /user1/ "/home/user1/webdoc/"
<Directory "/home/user1/webdoc">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

Alias /user2/ "/home/user2/webdoc/"
<Directory "/home/user2/webdoc">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>


for mod_rewrite only required in one place.
0
 
LVL 15

Assisted Solution

by:samri
samri earned 132 total points
ID: 8226376
hi mcdev,

this has been mentioned by mqlxx above.  Take a look at mod_userdir manual (http://httpd.apache.org/docs/mod/mod_userdir.html).

The one that you would be looking at would be

UserDir /home/*/public_html

Thus, you would only need to use
http://www.yourserver.com/user/page.html

no more tilde (~).

Almost similar to solution proposed by mcdev, except mine, will need the www stuff to be placed in a subdirectory under /home/user, whereas mcdev solution would allow access to files in user home directories.  If you are concern about security, pay special attention to this.

using mod_rewrite is great, but (personally) I would say that it would be overkill.  mod rewrite will have some overhead!

cheers.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

612 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