LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-07-2013, 04:15 AM   #1
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Rep: Reputation: Disabled
Redirect tilde addresses to non-tilde


Hello,

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

http://example.com/~cyro

I am trying to convert this URL pattern to

http://example.com/cyro

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

Code:
/webhome1/
/webhome2/
/webhome3/
and user cyro's files are stored in

Code:
/webhome2/cyro/public_html
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.
 
Old 01-07-2013, 06:37 AM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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.
 
Old 01-07-2013, 07:10 AM   #3
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
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 example.com/~cyro to cyro.example.com. In any case, I tried to make RewriteMap method work on directories and I got no result.

The guide I have found is here: https://lopsa.org/node/677

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

Code:
$> echo cyro | /etc/local/find-a-user
/webhome2/cyro
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:

Code:
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?

Last edited by Cyrolancer; 01-07-2013 at 09:19 PM. Reason: added details and corrected typo mistakes
 
Old 01-07-2013, 03:47 PM   #4
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
You don't need to redirect, you can just rewrite what the user sees in the location if you want.
 
Old 01-07-2013, 09:17 PM   #5
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by kbp View Post
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.
 
Old 01-07-2013, 09:17 PM   #6
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
Oops! Double post. Sorry about that.

Last edited by Cyrolancer; 01-07-2013 at 09:18 PM.
 
Old 01-08-2013, 06:00 AM   #7
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Have a read of the doco, let us know if you still can't get it working
 
Old 01-08-2013, 06:03 AM   #8
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
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
 
Old 01-09-2013, 02:42 AM   #9
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
Hello again,

I couldn't make it

Let me give some info about my config and logs.

vhost file:
Code:
....
....
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
Code:
[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:
Code:
X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [example.com/sid#7f7dd7630708][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] [example.com/sid#7f7dd7630708][rid#7f7dd7682a20/initial] (2) rewrite '/cyro/' -> '/webhome2/cyro/public_html'
X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [example.com/sid#7f7dd7630708][rid#7f7dd7682a20/initial] (2) local path result: /webhome2/cyro/public_html
X.X.X.X - - [09/Jan/2013:10:27:23 +0200] [example.com/sid#7f7dd7630708][rid#7f7dd7682a20/initial] (1) go-ahead with /webhome2/cyro/public_html [OK]
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [example.com/sid#7f7dd7630708][rid#7f7dd7688a50/subreq] (2) init rewrite engine with requested uri /cyro/index.html
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [example.com/sid#7f7dd7630708][rid#7f7dd7688a50/subreq] (3) applying pattern '^(.*)$' to uri '/cyro/index.html'
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [example.com/sid#7f7dd7630708][rid#7f7dd7688a50/subreq] (4) RewriteCond: input='/cyro/index.html' pattern='!-f' => matched
X.X.X.X - - [09/Jan/2013:10:27:24 +0200] [example.com/sid#7f7dd7630708][rid#7f7dd7688a50/subreq] (4) RewriteCond: input='/cyro/index.html' pattern='!^/~' => matched
I still couldn't make it work. I call http://example.com/cyro 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.
 
Old 01-09-2013, 02:55 AM   #10
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
I'll have a play and get back to you
 
1 members found this post helpful.
Old 01-09-2013, 03:03 AM   #11
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
Thank you Waiting your for your answer.
 
Old 01-09-2013, 04:25 AM   #12
Cyrolancer
Member
 
Registered: Jan 2012
Distribution: Debian
Posts: 52

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Tilde / back-tick key not giving me a tilde or back-tic. Ubuntu 10.04 on Macbook Pro BrianK Linux - Laptop and Netbook 3 09-01-2015 09:14 PM
[SOLVED] Using tilde and spaces youarefunny Linux - General 5 05-27-2010 10:38 AM
Tilde name shortening steveel Slackware 6 11-21-2005 03:55 AM
tilde in X nva Linux - General 2 06-30-2003 11:12 AM
Filenames with tilde rovoreed Programming 2 08-08-2001 04:53 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration