I'm running wildcard subdomains. the goal from the website is to operate an online subdomain. exactly what the functionality ought to be is the fact that once the files in the primary site are known as they'll be rewritten for that clean Web addresses. However when i'm calling exactly the same files make up the subdomain like abc.doamin.com/my-file.php then this ought to be rewritten enjoy it is asking that file by having an argument of subdoamin like domain.com/my-file.php?var=abc. Presently things i have accomplished for the file call is

Options +FollowSymLinks
RewriteEngine on

## Redirecting all non-www domains to www.domain.com
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC,L]


RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING}  ^$
RewriteRule ^(.*)$   http://www.domain.com%{REQUEST_URI}?var=%1 [L]


RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING}  !^$
RewriteRule ^(.*)$   http://www.domain.com%{REQUEST_URI}?%{QUERY_STRING}&var=%1 [L]



RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING}  ^$
RewriteRule ^(.*)$   http://www.domain.com/index.php?subdomain=%1 [L]


RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteCond %{QUERY_STRING}  !^$
RewriteRule ^(.*)$   http://www.domain.com%{REQUEST_URI}?%{QUERY_STRING}&subdomain=%1 [L]

This really is tossing a 500 internal error for that file call.

Rule set 4 will overlap with rule set 1 and a pair of. I suspect this really is leading to the problem. And So I think all 3 need an additional RewriteCond check up on REQUEST_URI.

Really you should not need rule set 4. Just including index.php like a default should have the desired effect. Unless of course obviously you wouldn't want URL's like http://www.domain.com/?var=xyz, within this situation you'll need rule 4, but you have to split it into 2 Body having a QUERY_STRING and something without, much like rule 1 and a pair of

Also, is not %1 in the regex within the rewriteRule itself and never the preceeding rewriteConds? If that's the case your regex is wrong, because it will be setting the var= towards the entire original URL.

Searching within the error log may be beneficial as you'll have the reason behind the 500 error.

Edit: Ok, try something similar to this (not examined)

## Redirecting all non-www domains to www.domain.com
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L,QSA]

## Redirecting / requests to index.php
# Note: Use the QSA flag for handling with or without query string
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^(.*)$   http://www.domain.com/index.php?var=%1 [L,QSA]

## Redirecting /something requests to index.php
# Note: Use the QSA flag for handling with or without query string
RewriteCond %{REQUEST_URI} ^/.+$
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^(.*)$   http://www.domain.com%{REQUEST_URI}?var=%1 [L,QSA]