-   Linux - Server (
-   -   Redirect tilde addresses to non-tilde (

Cyrolancer 01-07-2013 04:15 AM

Redirect tilde addresses to non-tilde

I am running a web server with mod_userdir enabled. The system works like this:

I am trying to convert this URL pattern to

In my configuration, the home directories of the users are mounted like,



and user cyro's files are stored in


Other users are seperated into other webhome directories and it is impossible for me to change this configuration.

Is it somehow possible to convert the tilde links to non-tilde in my configuration?

Thanks a lot.

kbp 01-07-2013 06:37 AM

If the webhomes are not real unix home dirs then you should disable mod_homedir and use mod_rewrite to redirect requests to the appropriate location. You'll need to be able to programatically determine the relevant location so you can use a regex in the rewrite rule.

Cyrolancer 01-07-2013 07:10 AM

It is possible to use custom directories in mod_userdir configuration. That's how it is working right now. Now, I am trying convert tilde addresses to non-tilde addresses and completely disable mod_userdir.

There are some guides on the net, using RewriteMap etc. but generally they convert to In any case, I tried to make RewriteMap method work on directories and I got no result.

The guide I have found is here:

I managed to build a script that gets in the input from stdin and echoes the output. An example is below:


$> echo cyro | /etc/local/find-a-user

However, I couldn't make it. It just doesn't work as expected. I couldn't understand what I am doing wrong.

Additionally, I tried some other rules like:


RewriteRule /([a-z0-9]+) /$1 [R]
The DocumentRoot I use for my domain (without the tildes) is /home/web/public_html. The above rule does not work, I think due to having no physical location like /home/web/public_html/cyro.

I have stuck at this point. Do you have any ideas?

kbp 01-07-2013 03:47 PM

You don't need to redirect, you can just rewrite what the user sees in the location if you want.

Cyrolancer 01-07-2013 09:17 PM


Originally Posted by kbp (Post 4864904)
You don't need to redirect, you can just rewrite what the user sees in the location if you want.

That's the exact point that I stuck at.

Cyrolancer 01-07-2013 09:17 PM

Oops! Double post. Sorry about that. :(

kbp 01-08-2013 06:00 AM

Have a read of the doco, let us know if you still can't get it working

Cyrolancer 01-08-2013 06:03 AM

I have already read the docs, but I think I should have some Apache logs and done a small addition to my "find-a-user" script. I will post the results.

Thanks :)

Cyrolancer 01-09-2013 02:42 AM

Hello again,

I couldn't make it :)

Let me give some info about my config and logs.

vhost file:

DocumentRoot /home/web/public_html
RewriteEngine on

RewriteMap users prg:/etc/apache2/sites-available/find-a-user

RewriteCond %{REQUEST_FILENAME} !-f
# Preserve tilde addresses
RewriteCond %{REQUEST_URI} !^/~
# Preseve direct domain access
RewriteCond (${users:$1}) !NULL
RewriteRule ^(.*)$ ${users:$1}/public_html

Apache sends a request to find-a-user script like this: /cyro/

And my script converts it into: /webhome2/cyro

Apache error.log

[Wed Jan 09 10:26:24 2013] [notice] caught SIGTERM, shutting down
[Wed Jan 09 10:26:24 2013] [warn] mod_rewrite: Running external rewrite maps without defining a RewriteLock is DANGEROUS!
[Wed Jan 09 10:26:24 2013] [notice] Apache/2.2.16 (Debian) configured -- resuming normal operations

I am going to define RewriteLock file, after I make it run.

RewriteLog file:

X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [][rid#7f7dd7682a20/initial] (5) map lookup OK: map=users key=/cyro/ -> val=/webhome2/cyro
X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [][rid#7f7dd7682a20/initial] (2) rewrite '/cyro/' -> '/webhome2/cyro/public_html'
X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [][rid#7f7dd7682a20/initial] (2) local path result: /webhome2/cyro/public_html
X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [][rid#7f7dd7682a20/initial] (1) go-ahead with /webhome2/cyro/public_html [OK]
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [][rid#7f7dd7688a50/subreq] (2) init rewrite engine with requested uri /cyro/index.html
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [][rid#7f7dd7688a50/subreq] (3) applying pattern '^(.*)$' to uri '/cyro/index.html'
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [][rid#7f7dd7688a50/subreq] (4) RewriteCond: input='/cyro/index.html' pattern='!-f' => matched
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [][rid#7f7dd7688a50/subreq] (4) RewriteCond: input='/cyro/index.html' pattern='!^/~' => matched

I still couldn't make it work. I call from the browser and it keeps waiting. After I reload Apache, I get 403 error.

I think this is a permissions problem, but I still don't know how to solve it, what permissions I should give.

kbp 01-09-2013 02:55 AM

I'll have a play and get back to you

Cyrolancer 01-09-2013 03:03 AM

Thank you :) Waiting your for your answer.

Cyrolancer 01-09-2013 04:25 AM

Hello again,

I have solved the problem finally. The "find-a-user" script is the main cause of the problem. I have integrated it in a different way and the problem seems solved. This script is specific to my needs and I don't want to share it. Sharing such a script will be a security problem but if somebody has a problem in implementing such a system, I will gladly help.

Thank you for your help and support kbp.

All times are GMT -5. The time now is 01:45 AM.