2011-11-30 127 views
1

我试图子域重定向到子文件夹 我有3个指向一个名为“测试”放置在根目录(/试验)重定向子域的子文件夹与htaccess的

subdomain1.mysite.com 
    subdomain2.mysite.com 
    subdomain3.mysite.com 

in test i have 3 folders `/test/subdomain1 , /test/subdomain2, /test/subdomain3` 

what i want is that: 
when i go to subdomain1.mysite.com it should be reading from: /test/subdomain1 
when i go to subdomain2.mysite.com it should be reading from: /test/subdomain2 
when i go to subdomain3.mysite.com it should be reading from: /test/subdomain3 

here is my htaccess used - placed in the folder "/test" and i think here is the problem!!: 

    Options -Indexes 
    <IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteBase/
    RewriteCond %{HTTP_HOST} ^subdomain1.mysite.com$ [NC] 
    RewriteRule ^(.*)$ subdomain1/$1 [L,QSA] 
    RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC] 
    RewriteRule ^(.*)$ subdomain2/$1 [L,QSA] 
    RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC] 
    RewriteRule ^(.*)$ subdomain3/$1 [L,QSA] 
    </IfModule> 

i am getting a "500 Internal Server Error" when accessing any subdomain... 

does RewriteBase works in subfolders ? if not placed the root ? 

any idea? 

thanks 
+0

是''
在这一行'重写规则^ $(*)。 subdomain2/$ 1 [L,QSA]
'这里的错误还是在你的htaccess文件中? –

+0

啊不是马特它的拼写错误我删除它! –

回答

0

文件夹的子域我相信,500错误是因为你没有逃脱的网址您.

RewriteCond %{HTTP_HOST} ^subdomain1.mysite.com$ [NC] 

应该

RewriteCond %{HTTP_HOST} ^subdomain1\.mysite\.com$ [NC] 
+0

谢谢你Matt的帮助! 我试图逃避的点,但仍然有相同的错误! 我的域名包含“ - ”是否意味着什么? –

+0

htaccess被放置在文件夹“测试”,我把它放在根级别并更改RewriteBase? –

+0

将htaccess移到根目录,并尝试转义连字符。 –

0

有一个错误...

RewriteBase/
RewriteCond %{HTTP_HOST} ^subdomain1.mysite.com$ [NC] 
RewriteRule ^(.*)$ subdomain1/$1 [L,QSA] 
RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC] 
RewriteRule ^(.*)$ subdomain2/$1 [L,QSA] 
RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC] 
RewriteRule ^(.*)$ subdomain3/$1 [L,QSA] 

最后两行:

RewriteCond %{HTTP_HOST} ^subdomain2.mysite.com$ [NC] 
RewriteRule ^(.*)$ subdomain3/$1 [L,QSA] 

subdomain2代替subdomain3