sub.domain.com/user redirection issue

Using a single web hosting account to host multiple sites

sub.domain.com/user redirection issue

Postby meetn2veg » Sun Nov 05, 2006 9:46 am

After having "searched" other forums, the results usually gave me the whole forum! After having looked through most of those entries, I am still none the wiser! After having searched the net, I only found the same info, re-written from the Apache page on mod-rewrite! Although I found http://www.modrewrite.com forum very useful and more informative than most, I'm still none the wiser!!! I've also posted this at the Powweb (my host) forum to see what they can come up with!

The following excerpts of .htaccess code I've taken from several posts within this forum, and they don't seem to work for my situation. So, here goes with you guys at mod_rewrite.

The 1st thing I'll say is that I'm developing on my local pc using Apache 2 and have a whole lot of VirtualHosts set up in the httpd.conf file.

The 2nd thing I'll say is that once I have achieved what I'm looking to do, I'll need to adapt it to work correctly on the Powweb servers (running Apache 1.3 - bummer!)

I've got several genuine sub domains that I do not want to be redirected - eg: admin.localhost.com, ads.localhost.com, img.localhost.com, etc....

The entry in my D:/www.localhost.com/htdocs/.htaccess file is:
Options +FollowSymlinks
RewriteEngine on
# this ignores http://www.localhost.com, admin.localhost.com, etc...
# Any subdomains that are NOT related to a user account must
# be included here to avoid being redirected in error
RewriteCond %{HTTP_HOST} !^www\.localhost\.com$ [NC]
RewriteCond %{HTTP_HOST} !^admin\.localhost\.com$ [NC]
RewriteCond %{HTTP_HOST} !^ads\.localhost\.com$ [NC]


I also have several "groups" (sub domains) created, such as hotels.localhost.com, bars.localhost.com, workers.localhost.com etc... which, when entered into the browser's address bar will display their respective index page.

The next entry in my D:/www.localhost.com/htdocs/.htaccess file is:
# Anything else must be a subdomain
RewriteCond %{HTTP_HOST} ^([a-z0-9-]+)\.localhost\.com$ [NC]


If someone were to type in "bars.localhost.com/mybar" I'd like to achieve the following;

take the sub domain part of the address (bars) and the username part (/mybar) and silently redirect to one file (D:/www.localhost.com/htdocs/redirect.pl) which will quiz a MySQL database for the appropriate information on My Bar therefore serving up the appropriate page. I'm not too bothered what appears as a result in the address bar, but I'd at least prefer to stay at bars.localhost.com/mybar irrispective of the actual URL. If at all possible, I'd also like to offer mybar.localhost.com, but I'm aware that each username (ie:mybar) must be unique in this situation (at present, each username must be unique within each group, therefore allowing the same username to exist within the "bars" group and also the "hotels" group).

I'm sure that I have a small issue with my server and httpd.conf file as localhost and http://www.localhost.com go to the same place, but I'll leave that for another day :confused:

I have the following within the httpd.conf file (as well as ads, admin, etc...):
<VirtualHost *:80>
ServerName bars.localhost.com
DocumentRoot D:/www.localhost.com/bars/htdocs
Options Includes +Indexes
<Directory "D:/www.localhost.com/bars/htdocs">
Options +ExecCGI +Indexes
</Directory>
</VirtualHost>

All their respective directories physically exist on D:/

What do I need to put into the D:/www.localhost.com/htdocs/.htaccess file (http://www.localhost.com) and what is needed within the D:/www.localhost.com/bars/htdocs/.htaccess file (bars.localhost.com) ???

The last entry in the D:/www.localhost.com/htdocs/.htaccess file is;
# A directory with the name of the subdomain must exist
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^([^\.]+)/?$ /redirect.pl?group=%1&user=$1 [L]

At the moment and just for testing purposes, the redirect.pl file only outputs the 2 variables passed to it within the redirected URL - which at the moment it doesn't but only because I've got the problem that nothing is being redirected!!!

Any help (with explainations os the code/regex's etc) would be most helpful as I haven't got much hair left to pull out over this problem!
meetn2veg
 
Posts: 2
Joined: Sun Nov 05, 2006 8:22 am
Location: Andorra

Postby richardk » Mon Nov 06, 2006 11:30 am

So redirect.pl is in d:/www.localhost.com/htdocs? Then really you need the sub domains you want rewritten pointed to d:/www.localhost.com/htdocs because mod_rewrite can't rewrite below the (sub) domain's document root. Is that how it's setup on your host? You'll probably need a redirect.pl file in each sub domain document root to include the main one, or if you have mod_proxy you can probably use that.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby meetn2veg » Tue Nov 07, 2006 4:01 am

Richard - thanks for your reply.

What I'm hoping to achieve is *not* to have redirect.pl under each sub domain.

You've just made me look at it from another angle!!! Of course - I'm going to need an .htaccess file per sub domain which will do the redirect to the "redirect.pl" file - doh!

I might have to rethink this - but I'm sure it's still possible to have one redirect.pl file shared by all sub domains without changing the URL in the client browser?!?

Thanks for that - sometimes you can't see the wood for the trees!

Regards,
Richard
meetn2veg
 
Posts: 2
Joined: Sun Nov 05, 2006 8:22 am
Location: Andorra

Postby richardk » Tue Nov 07, 2006 8:39 am

I might have to rethink this - but I'm sure it's still possible to have one redirect.pl file shared by all sub domains without changing the URL in the client browser?!?

You'd either need mod_proxy or to change the document roots. Mod_rewrite cannot rewrite outside the current (sub) domain's document root.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rkrause » Sat Dec 02, 2006 9:12 am

I might have to rethink this - but I'm sure it's still possible to have one redirect.pl file shared by all sub domains without changing the URL in the client browser?!?


Actually the ScriptAlias directive should work for that.

--Randall
rkrause
 
Posts: 1
Joined: Sat Dec 02, 2006 9:10 am
Location: Illinois


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 98 guests

cron