?
Solved

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

Posted on 2003-03-26
8
Medium Priority
?
472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

777 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