need help with /~usersite

New to mod_rewrite? This is a good place to start.

need help with /~usersite

Postby billylucas » Wed Jun 03, 2009 12:24 am

Hello I have a RHEL5 server with a special hosting panel installed. Basically what the situation is I have some legacy usersites that have been migrated onto the server and need to use mod_rewrite to do some url changing.

what I want is

navigating to www.example.com/~billy redirects you to users.example.com/billy

I have a handfull of these users and is there some sort of universal way of making it so that the content after the tilde is matched to the redirect? for example

going to www.example.com/~billy goes to users.example.com/billy and then typing in www.example.com/~billy1 goes to users.example.com/billy1 accomplishing this with only a few lines of rules and conditions? I had this working once before but the server died and lost the .htaccess file.

The other fact is, www.example.com and users.example.com live in seperate root directories. Any help with this will be greatly appreciated.
billylucas
 
Posts: 6
Joined: Tue Jun 02, 2009 11:28 pm

Postby richardk » Wed Jun 03, 2009 12:38 pm

You should be able to do that with RedirectMatch (mod_dir)
Code: Select all
RedirectMatch 301 ^~([^/]+)(/(.*))?$ http://$1.example.com/$3
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby billylucas » Wed Jun 03, 2009 1:11 pm

ok, that resembles what I had a while ago in there, but I am new to .htaccess files and mod rewrite, I am coming off of an ISAPI background.

this is currently my .htaccess file output

Code: Select all
Options +FollowSymLinks
RewriteEngine on
RedirectMatch 301 ^~([^/]+)(/(.*))?$ http://$1.users.vcnet.com/$3
RewriteRule (.*) http://www.iswest.com/ [R=301,L]


when I comment out the aliasing in the httpd.conf, I can't reach the tilde site.

I have the 301 redirect in there because everything BUT the tilde sites should forward to iswest.com

once again, any help is appreciated.
billylucas
 
Posts: 6
Joined: Tue Jun 02, 2009 11:28 pm

Postby richardk » Wed Jun 03, 2009 1:19 pm

Where is the .htaccess file?
What aliasing in the httpd.conf file?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^~([^/]+)(/(.*))?$ http://$1.users.vcnet.com/$3 [R=301,L]

RewriteRule .* http://www.iswest.com/? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby billylucas » Wed Jun 03, 2009 1:37 pm

ok that seemed to help, it forwards everything but the tildes to iswest.com however the url stays the same for example, when I type "www.vcnet.com/~andy" it stays at that URL instead of going to "users.vcnet.com/andy"

to answer other questions, I have the .htaccess file inside of the vcnet.com root directory, all domains live in their own root directory.

As far as the alias inside the httpd config I had this but commented it out to test the mod_rewrites

Code: Select all
Alias /~andy /hsphere/local/home/iswebmaster0/users.vcnet.com/andy
billylucas
 
Posts: 6
Joined: Tue Jun 02, 2009 11:28 pm

Postby billylucas » Wed Jun 03, 2009 4:05 pm

ok if I place this line in the virtual host entry for iswest.com

this is for a different scenario, similar thing though

when going to www.iswest.com/~mattp I want it to rewrite to users.iswest.com/mattp

Code: Select all
RewriteRule ^/~(.+)$ http://users.iswest.com/$1 [R=301,L]



any thoughts?
billylucas
 
Posts: 6
Joined: Tue Jun 02, 2009 11:28 pm

Postby billylucas » Wed Jun 03, 2009 11:29 pm

ok, more things uncovered now. I added logging for mod rewrite and stumbled across this.

this is what was output when I tailed the log file when the rule I posted above was placed in the .htaccess file.

Code: Select all
76.95.177.65 - - [03/Jun/2009:23:52:03 --0700] [www.vcnet.com/sid#9af7860][rid#a6a1798/initial] (2) init rewrite engine with requested uri /~annag
76.95.177.65 - - [03/Jun/2009:23:52:03 --0700] [www.vcnet.com/sid#9af7860][rid#a6a1798/initial] (1) pass through /~annag
76.95.177.65 - - [03/Jun/2009:23:52:03 --0700] [www.vcnet.com/sid#9af7860][rid#a6a1798/initial] (3) [perdir /hsphere/local/home/iswebmaster0/vcnet.com/] strip per-dir prefix: /hsphere/local/home/iswebmaster0/vcnet.com/~annag -> ~annag
76.95.177.65 - - [03/Jun/2009:23:52:03 --0700] [www.vcnet.com/sid#9af7860][rid#a6a1798/initial] (3) [perdir /hsphere/local/home/iswebmaster0/vcnet.com/] applying pattern '^/~(.+)$' to uri '~annag'
76.95.177.65 - - [03/Jun/2009:23:52:03 --0700] [www.vcnet.com/sid#9af7860][rid#a6a1798/initial] (1) [perdir /hsphere/local/home/iswebmaster0/vcnet.com/] pass through /hsphere/local/home/iswebmaster0/vcnet.com/~annag


and when I place the same rule inside of the virtual host config file for the site.

Code: Select all
76.95.177.65 - - [03/Jun/2009:23:54:00 --0700] [www.vcnet.com/sid#9bbd210][rid#a6ecb58/initial] (2) init rewrite engine with requested uri /~annag
76.95.177.65 - - [03/Jun/2009:23:54:00 --0700] [www.vcnet.com/sid#9bbd210][rid#a6ecb58/initial] (3) applying pattern '^/~(.+)$' to uri '/~annag'
76.95.177.65 - - [03/Jun/2009:23:54:00 --0700] [www.vcnet.com/sid#9bbd210][rid#a6ecb58/initial] (2) rewrite '/~annag' -> 'http://users.vcnet.com/annag'
76.95.177.65 - - [03/Jun/2009:23:54:00 --0700] [www.vcnet.com/sid#9bbd210][rid#a6ecb58/initial] (2) explicitly forcing redirect with http://users.vcnet.com/annag
76.95.177.65 - - [03/Jun/2009:23:54:00 --0700] [www.vcnet.com/sid#9bbd210][rid#a6ecb58/initial] (1) escaping http://users.vcnet.com/annag for redirect
76.95.177.65 - - [03/Jun/2009:23:54:00 --0700] [www.vcnet.com/sid#9bbd210][rid#a6ecb58/initial] (1) redirect to http://users.vcnet.com/annag [REDIRECT/301]


as always, any thoughts will help.
billylucas
 
Posts: 6
Joined: Tue Jun 02, 2009 11:28 pm

Postby richardk » Thu Jun 04, 2009 1:26 pm

Code: Select all
applying pattern '^/~(.+)$' to uri '~annag'

Remove the slash from the pattern and it will match.

For /~userA to http://users.example.com/userA (in a .htaccess file)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^~([^/]+)(/(.*))?$ http://users.example.com/$1/$3 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby billylucas » Thu Jun 04, 2009 1:57 pm

I bow to your knowledge sir. I thank you and would shake your hand if I could. I am doing my best to learn about the whole admin side of apache. Anyways once again, thank you.
billylucas
 
Posts: 6
Joined: Tue Jun 02, 2009 11:28 pm


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 112 guests

cron