Forum Moderators: phranque
i am using the following code to redirect any subfolder to subdomain
i.e.
if someone types [test.domain.com...] then it will point to [domain.com...]
so it looks like a subdomain
======================================================
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^.htaccess$ - [f]
RewriteCond %{HTTP_HOST}!^www.domain.com
RewriteCond %{HTTP_HOST}!^ftp.domain.com
RewriteCond %{HTTP_HOST}!^mail.domain.com
RewriteCond %{HTTP_HOST} ^([^.]*).domain.com
RewriteRule (.*) /%1/$1 [L]
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
=======================================================
now the problem is below
suppose two subdomains are there, i meant that to folders
domain.com/sd1 and domain.com/sd2
both are working well as
sd1.domain.com and sd2.domain.com
now suppose, i m goping to make one folder under sd1
i give the name 'sd2'
so url looks like sd1.domain.com/sd2/
but it will not work because i have already one subdomain named sd2
so anything under sd1.domain.com/sd2/ will be treated as domain.com/sd2/
my code ignores the subdomain part
anyone who knows this stuff please help me
There is no "perfect" solution, as all you can do is to minimize the chances for for "interference" by picking "likely-unique" subdomain-subdirectory names. You can either prepend a "tag" on the subdomain-subdirectory filepaths to distinguish them from main-domain subdirectories, or you can move all subdomain-subdirectories into one uniquely-named subdirectory, and put all the subdomain-subdirectories there.
As examples:
RewriteCond %{HTTP_HOST} !^(www¦ftp¦mail)\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /subd_%1/$1 [L]
RewriteCond %{HTTP_HOST} !^(www¦ftp¦mail)\.example\.com
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule (.*) /sub-d/%1/$1 [L]
Note that I compressed your three RewriteConds to one by using the "local OR", and escaped the literal periods in the regular expressions as recommended.
Also, replace the broken pipe "¦" characters with solid pipe characters before use; Posting on this forum modifies the pipe characters.
Jim