public_html web server - without mod_userdir

Hell, what does the title mean??

It means this :

Allow people to put files in the public_html folder in their home directories and allow it to be seen through the web server of that server in this format : http://servername/~username/hisorherfiles

Most people use mod_userdir to allow ~username directories in their webservers. However, there is simple rewrite rule workaround that eliminates the need for mod_userdir.  I needed this because we had the home directories on the server, but the users had no login accounts on the server and they needed their public_html to work.

Here is how it goes :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#First, disable the default thing : 
<IfModule mod_userdir.c>
UserDir disable
</IfModule>
#Then the rewrite rule
</pre>
<pre>#To prevent access to files ~something.html and #something.html#
<Files ~ ".*(~|#)$">
Order allow,deny
Deny from all
</Files>
#To show public_html access
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/~\w+/.*$
RewriteRule /~(\w+)/(.*) /webteam/$1/public_html/$2
RewriteCond %{REQUEST_URI} ^/~\w+$
RewriteRule /~(\w+) /webteam/$1/public_html/
#To enable .htaccess rules in public_html
<Directory /webteam/*/public_html>
AllowOverride All
</Directory>
Author

Sahil Ahuja

Posted on

2008-05-03

Updated on

2020-12-21

Licensed under

Comments