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
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!