redirecting subdomain to subfolders with .htaccess

只谈情不闲聊 提交于 2019-12-11 13:27:34

问题


i am trying to redirect a subdomain to a subfolder i have 3 sub-domains pointing to a folder named "test" placed on the root (/test)

    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

回答1:


I believe the 500 error is because you haven't escaped your . in the URL:

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

should be

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



回答2:


There is an error...

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]

last 2 lines:

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

subdomain2 instead of subdomain3



来源:https://stackoverflow.com/questions/8324970/redirecting-subdomain-to-subfolders-with-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!