在.htaccess里面配置
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^another.site.com$ [NC]
RewriteCond %{REQUEST_URI} !^/another/
RewriteRule ^(.*)$ another/$1 [QSA,PT,L]
这个表示。如果遇到 another.site.com 就定向到目录下的another 目录里面去访问
1 打开重写引擎
2重写目录的基准目录 /
3 重写条件1是 主机名是another.site.com 正则
4 重写条件2是 URI 不包含another这个目录 (重定向到这个目录以后,URI里面肯定要包含another,被重写一次后第二次进来条件就不满足了,所以就不跳了)。
5 将后面访问的URI 替换为another/URI。$1就是替换正则的第一组
另外注意Rewrite的那个是由上到下实现的,要注意前后顺序。
之前因为我还有一个重写规则 全部通过index.php来处理,他在前面,导致我后面的这个 URI错误了。所以我把他放前面了
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]