【问题标题】:redirecting subdomain to subfolders with .htaccess使用 .htaccess 将子域重定向到子文件夹
【发布时间】:2012-01-09 15:09:15
【问题描述】:

我正在尝试将子域重定向到子文件夹 我有 3 个子域指向位于根目录 (/test) 上的名为“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

【问题讨论】:

  • 这一行的&lt;br/&gt; RewriteRule ^(.*)$ subdomain2/$1 [L,QSA]&lt;br/&gt; 是这里的错误还是在您的 htaccess 文件中?
  • 啊不,马特这是一个拼写错误,我删除了它!

标签: .htaccess redirect subdomain mod-rewrite


【解决方案1】:

我相信 500 错误是因为您没有在 URL 中转义您的 .:

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

应该是

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

【讨论】:

  • 感谢马特的帮助!!我试图逃避这些点,但仍然有同样的错误!!我的域包含一个“-”这意味着什么?
  • htaccess 放在文件夹“test”中,我是否将它放在根级别并更改 RewriteBase?
  • 将 htaccess 移至根目录并尝试转义连字符。
  • 我通过添加RewriteEngine On Options +FollowSymLinks RewriteRule ^google\.html http://www.google.com/? [R=301,L]确保模式重写工作正常
  • 嗨,马特!正如你所说的那样工作!但如果我在文件夹 subdomain1、subdomain2、subdomain3 中有一个 index.php 文件!但在 subdomain2 中,我收到 500 内部服务器错误,因为我没有索引,我将有一个包含图像的文件夹列表...
【解决方案2】:

有一个错误...

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

【讨论】:

    猜你喜欢
    • 2012-11-23
    • 2017-03-05
    • 2013-11-08
    • 1970-01-01
    • 2014-03-17
    • 2016-02-08
    • 1970-01-01
    • 2013-12-03
    • 2017-03-06
    相关资源
    最近更新 更多