views:

1130

answers:

1

I have Wild Card Subdomains on, however I just do not know mod_rewrite to the extent that is required to write this. Can anyone tell me how to make it so anything other than www and nothing go to the main site but any subdomain other than that go to /script/index.php?username=$username?

+1  A: 

Where does the $username variable supposed to come from??

Supposing the URL of the main site is http://www.example.com/main_site.php and that you are using this outside Directory context (ie, not in .htaccess nor in a <Directory> directive). If it is in .htaccess remove the leading / (make it just main_site.php, for example).

I reckon this will not work right away because there are many non clear variables (where does username come from?, what to do about the rest of the request, pass it as a parameter?, is this htaccess or main config?), but hopefully will get you an idea:

#Turn on the rewrite engine
RewriteEngine On
#Check accessed domain, if it's either www.example.com or
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC,OR]
#example.com
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
#and the requested URL does not contain script you'll be accessing to avoid looping
RewriteCond %{REQUEST_URI} !main_site.php
#Then we tell that everything matching the above will go to main_site.php
RewriteRule ^ /main_site.php [L]
#If the request is not asking for main_site.php nor index.php
RewriteCond %{REQUEST_URI} !main_site.php
RewriteCond %{REQUEST_URI} !index.php
#We go to /script/index.php (username will be empty, becase we don't know 
#where to get it from)
RewriteRule ^ /script/index.php?username=$username [L]
Vinko Vrsalovic
The username is from the sub domain.
Darren22
And what if it's nothing (ie, just domain.com)?
Vinko Vrsalovic